Print last received message in timeout exceptions
[lsp-test.git] / src / Language / Haskell / LSP / Test / Exceptions.hs
index b1e0635e31b435b6a8e480e19b83b43fdab6802b..88cf57d11ed6910391856ed85ffe9b244fcc5e26 100644 (file)
@@ -11,7 +11,8 @@ import Data.List
 import qualified Data.ByteString.Lazy.Char8 as B
 
 -- | An exception that can be thrown during a 'Haskell.LSP.Test.Session.Session'
-data SessionException = Timeout
+data SessionException = Timeout (Maybe FromServerMessage)
+                      | NoContentLengthHeader
                       | UnexpectedMessage String FromServerMessage
                       | ReplayOutOfOrder FromServerMessage [FromServerMessage]
                       | UnexpectedDiagnostics
@@ -23,7 +24,12 @@ data SessionException = Timeout
 instance Exception SessionException
 
 instance Show SessionException where
-  show Timeout = "Timed out waiting to receive a message from the server."
+  show (Timeout lastMsg) =
+    "Timed out waiting to receive a message from the server." ++
+    case lastMsg of
+      Just msg -> "\nLast message received: " ++ show msg
+      Nothing -> mempty
+  show NoContentLengthHeader = "Couldn't read Content-Length header from the server."
   show (UnexpectedMessage expected lastMsg) =
     "Received an unexpected message from the server:\n" ++
     "Was parsing: " ++ expected ++ "\n" ++