git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
[psc-ide] Fix #2504
c9446fbChristoph Hegemann
psc-ide-server/Main.hs+12−4
@@ -29,6 +29,7 @@ import "monad-logger" Control.Monad.Logger
29import qualified Data.Text.IO as T
29import qualified Data.Text.IO as T
30import qualified Data.ByteString.Lazy.Char8 as BS8
30import qualified Data.ByteString.Lazy.Char8 as BS8
31import Data.Version (showVersion)
31import Data.Version (showVersion)
32+import GHC.IO.Exception (IOErrorType(..), IOException(..))
32import Language.PureScript.Ide
33import Language.PureScript.Ide
33import Language.PureScript.Ide.Command
34import Language.PureScript.Ide.Command
34import Language.PureScript.Ide.Util
35import Language.PureScript.Ide.Util
@@ -144,14 +145,21 @@ startServer port env = withSocketsDo $ do
144 -- $(logDebug) ("Answer was: " <> T.pack (show result))
145 -- $(logDebug) ("Answer was: " <> T.pack (show result))
145 liftIO (hFlush stdout)
146 liftIO (hFlush stdout)
146 case result of
147 case result of
147− Right r -> liftIO $ BS8.hPutStrLn h (Aeson.encode r)
148+ Right r -> liftIO $ catchGoneHandle (BS8.hPutStrLn h (Aeson.encode r))
148− Left err -> liftIO $ BS8.hPutStrLn h (Aeson.encode err)
149+ Left err -> liftIO $ catchGoneHandle (BS8.hPutStrLn h (Aeson.encode err))
149 Nothing -> do
150 Nothing -> do
150 $(logError) ("Parsing the command failed. Command: " <> cmd)
151 $(logError) ("Parsing the command failed. Command: " <> cmd)
151 liftIO $ do
152 liftIO $ do
152− T.hPutStrLn h (encodeT (GeneralError "Error parsing Command."))
153+ catchGoneHandle (T.hPutStrLn h (encodeT (GeneralError "Error parsing Command.")))
153 hFlush stdout
154 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)
155
163
156acceptCommand :: (MonadIO m, MonadLogger m, MonadError Text m)
164acceptCommand :: (MonadIO m, MonadLogger m, MonadError Text m)
157 => Socket -> m (Text, Handle)
165 => Socket -> m (Text, Handle)