Skip to content

Commit b8062a8

Browse files
andreiburdusagithub-actions
andauthored
kore-repl: If piped commands fail do not crash kore-repl (#2940)
* Handle errors in runExternalProcess * Cleanup createProcess usage Co-authored-by: dopamane [email protected] * Format with fourmolu Co-authored-by: github-actions <[email protected]>
1 parent 53309ed commit b8062a8

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

kore/src/Kore/Repl/Interpreter.hs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Control.Exception (
2828
displayException,
2929
throwIO,
3030
)
31+
import qualified Control.Exception as X
3132
import Control.Lens (
3233
(%=),
3334
(.=),
@@ -1241,15 +1242,11 @@ pipe cmd file args = do
12411242
}
12421243
runExternalProcess :: IORef ReplOutput -> String -> String -> IO ()
12431244
runExternalProcess pipeOut exec str = do
1244-
(maybeInput, maybeOutput, _, _) <- createProcess' exec
1245-
let outputFunc = maybe putStrLn hPutStr maybeInput
1246-
outputFunc str
1247-
case maybeOutput of
1248-
Nothing ->
1249-
hPutStrLn stderr "Error: couldn't access output handle."
1250-
Just handle -> do
1251-
output <- liftIO $ hGetContents handle
1252-
modifyIORef pipeOut (appReplOut . AuxOut $ output)
1245+
(Just hIn, Just hOut, _, _) <- createProcess' exec
1246+
hPutStr hIn str
1247+
`catch` \(X.SomeException e) -> hPutStrLn stderr (displayException e)
1248+
output <- liftIO $ hGetContents hOut
1249+
modifyIORef pipeOut (appReplOut . AuxOut $ output)
12531250
justPrint :: IORef ReplOutput -> String -> IO ()
12541251
justPrint outRef = modifyIORef outRef . appReplOut . AuxOut
12551252

0 commit comments

Comments
 (0)