Add withTimeout
[lsp-test.git] / src / Language / Haskell / LSP / Test / Exceptions.hs
index c130702bd15f2ed55d6776f7edaf4d525e72100a..c8ca4f98e3512526fad50e30e18151cd24d2cf28 100644 (file)
@@ -2,6 +2,7 @@ module Language.Haskell.LSP.Test.Exceptions where
 
 import Control.Exception
 import Language.Haskell.LSP.Messages
+import Language.Haskell.LSP.Types
 import Data.Aeson
 import qualified Data.ByteString.Lazy.Char8 as B
 
@@ -10,6 +11,8 @@ data SessionException = TimeoutException
                       | ReplayOutOfOrderException FromServerMessage [FromServerMessage]
                       | UnexpectedDiagnosticsException
                       | IncorrectApplyEditRequestException String
+                      | UnexpectedResponseError LspIdRsp ResponseError
+  deriving Eq
 
 instance Exception SessionException
 
@@ -17,8 +20,8 @@ instance Show SessionException where
   show TimeoutException = "Timed out waiting to receive a message from the server."
   show (UnexpectedMessageException expected lastMsg) =
     "Received an unexpected message from the server:\n" ++
-    "Expected: " ++ expected ++ "\n" ++
-    "Last message accepted: " ++ show lastMsg
+    "Was parsing: " ++ expected ++ "\n" ++
+    "Last message received: " ++ show lastMsg
   show (ReplayOutOfOrderException received expected) =
     "Replay is out of order:\n" ++
     -- Print json so its a bit easier to update the session logs
@@ -27,6 +30,8 @@ instance Show SessionException where
   show UnexpectedDiagnosticsException = "Unexpectedly received diagnostics from the server."
   show (IncorrectApplyEditRequestException msgStr) = "ApplyEditRequest didn't contain document, instead received:\n"
                                           ++ msgStr
+  show (UnexpectedResponseError lid e) = "Received an exepected error in a response for id " ++ show lid ++ ":\n"
+                                          ++ show e
 
 anySessionException :: SessionException -> Bool
 anySessionException = const True