Skip to content
Snippets Groups Projects
Commit 8b4abaac authored by Mr. Snow Ball / projects's avatar Mr. Snow Ball / projects :arrows_counterclockwise:
Browse files

Display exit code if non-polled script fails

parent a1e5557f
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,9 @@ import Pipes ...@@ -16,8 +16,9 @@ import Pipes
import Pipes.Safe (catchP) import Pipes.Safe (catchP)
import System.Exit import System.Exit
import System.IO hiding (stdin, stdout) import System.IO hiding (stdin, stdout)
import System.IO.Error (isEOFError)
import System.Process.Typed (Process, shell, setStdin, setStdout, import System.Process.Typed (Process, shell, setStdin, setStdout,
getStdin, getStdout, closed, createPipe, readProcessStdout, startProcess, stopProcess) getStdin, getStdout, closed, createPipe, readProcessStdout, startProcess, stopProcess, getExitCode)
pollScriptBlock :: Interval -> FilePath -> Block pollScriptBlock :: Interval -> FilePath -> Block
...@@ -39,16 +40,23 @@ pollScriptBlock interval path = runPollBlock' interval $ forever $ yieldBlockUpd ...@@ -39,16 +40,23 @@ pollScriptBlock interval path = runPollBlock' interval $ forever $ yieldBlockUpd
scriptBlock :: Bool -> FilePath -> Block scriptBlock :: Bool -> FilePath -> Block
-- The outer catchP only catches errors that occur during process creation -- The outer catchP only catches errors that occur during process creation
scriptBlock clickEvents path = catchP startScriptProcess handleError scriptBlock clickEvents path = catchP startScriptProcess (handleError Nothing)
where where
handleError :: IOException -> Block handleError :: Maybe ExitCode -> IOException -> Block
handleError e = do handleError exitCode exc = case result of
pushBlockUpdate . mkErrorOutput $ T.pack (show e) Left msg -> forever $ pushBlockUpdate $ mkErrorOutput msg
exitBlock Right x -> x
where
result = case (isEOFError exc, exitCode) of
(True, Just ExitSuccess) -> Right exitBlock
(True, Just (ExitFailure nr)) ->
Left $ "exit code " <> T.pack (show nr)
_ -> Left $ T.pack (show exc)
handleErrorWithProcess :: (Process i o e) -> IOException -> Block handleErrorWithProcess :: (Process i o e) -> IOException -> Block
handleErrorWithProcess process e = do handleErrorWithProcess process exc = do
exitCode <- getExitCode process
stopProcess process stopProcess process
handleError e handleError exitCode exc
startScriptProcess :: Block startScriptProcess :: Block
startScriptProcess = if clickEvents startScriptProcess = if clickEvents
then startScriptProcessWithEvents then startScriptProcessWithEvents
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment