@@ -29,6 +29,7 @@ import "monad-logger" Control.Monad.Logger
2929import qualified Data.Text.IO as T
3030import qualified Data.ByteString.Lazy.Char8 as BS8
3131import Data.Version (showVersion)
32+import GHC.IO.Exception (IOErrorType(..), IOException(..))
3233import Language.PureScript.Ide
3334import Language.PureScript.Ide.Command
3435import Language.PureScript.Ide.Util
@@ -144,14 +145,21 @@ startServer port env = withSocketsDo $ do
144145 -- $(logDebug) ("Answer was: " <> T.pack (show result))
145146 liftIO (hFlush stdout)
146147 case result of
147− Right r -> liftIO $ BS8.hPutStrLn h (Aeson.encode r)
148− Left err -> liftIO $ BS8.hPutStrLn h (Aeson.encode err)
148+ Right r -> liftIO $ catchGoneHandle (BS8.hPutStrLn h (Aeson.encode r))
149+ Left err -> liftIO $ catchGoneHandle (BS8.hPutStrLn h (Aeson.encode err))
149150 Nothing -> do
150151 $(logError) ("Parsing the command failed. Command: " <> cmd)
151152 liftIO $ do
152− T.hPutStrLn h (encodeT (GeneralError "Error parsing Command."))
153+ catchGoneHandle (T.hPutStrLn h (encodeT (GeneralError "Error parsing Command.")))
153154 hFlush stdout
154− liftIO (hClose h)
155+ liftIO $ catchGoneHandle (hClose h)
156+
157+catchGoneHandle :: IO () -> IO ()
158+catchGoneHandle =
159+ handle (\e -> case e of
160+ IOError { ioe_type = ResourceVanished } ->
161+ putText ("[Error] psc-ide-server tried interact with the handle, but the connection was already gone.")
162+ _ -> throwIO e)
155163
156164acceptCommand :: (MonadIO m, MonadLogger m, MonadError Text m)
157165 => Socket -> m (Text, Handle)