From 0ba7a3adcc5e539a31b5893bc956a39105e6a9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 22 Aug 2026 22:10:51 +0200 Subject: Shell: track exit code of the last command --- src/Script/Shell.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Script/Shell.hs') diff --git a/src/Script/Shell.hs b/src/Script/Shell.hs index 29e2324..f070de5 100644 --- a/src/Script/Shell.hs +++ b/src/Script/Shell.hs @@ -47,6 +47,7 @@ data ShellState = ShellState { shellWorkingDirectory :: FilePath , shellOldWorkingDirectory :: FilePath , shellExitOnError :: Bool + , shellLastExitCode :: ExitCode } data ShellStatement = ShellStatement @@ -134,17 +135,17 @@ executeCommand sei@ShellExecInfo {..} st pstdin pstdout pstderr scmd@ShellComman _ -> do return cur - ( getExitStatus, state' ) <- executeCommandProcess sei st (handledHandle pstdin') (handledHandle pstdout') (handledHandle pstderr') args cmdCommand + ( getExitStatus, st' ) <- executeCommandProcess sei st (handledHandle pstdin') (handledHandle pstdout') (handledHandle pstderr') args cmdCommand let failedWithStatus status = do when (shellExitOnError st) $ do liftIO $ putMVar seiStatusVar status throwError Failed - return state' + return st' { shellLastExitCode = status } mapM_ closeIfRequested [ pstdin', pstdout', pstderr' ] getExitStatus >>= \case Exited ExitSuccess -> do - return state' + return st' { shellLastExitCode = ExitSuccess } Exited status -> do outLine OutputChildFail (Just $ textProcName seiProcName) $ "failed at: " <> textSourceLine cmdSourceLine failedWithStatus status @@ -243,11 +244,12 @@ executeScript sei@ShellExecInfo {..} pstdin pstdout pstderr (ShellScript stateme { shellWorkingDirectory = nodeDir seiNode , shellOldWorkingDirectory = nodeDir seiNode , shellExitOnError = True + , shellLastExitCode = ExitSuccess } - _ <- (\f -> foldM f initialState statements) $ \st ShellStatement {..} -> do + finalState <- (\f -> foldM f initialState statements) $ \st ShellStatement {..} -> do executePipeline sei st (KeepHandle pstdin) (KeepHandle pstdout) (KeepHandle pstderr) shellPipeline - liftIO $ putMVar seiStatusVar ExitSuccess + liftIO $ putMVar seiStatusVar (shellLastExitCode finalState) spawnShell :: Node -> ProcName -> ShellScript -> TestRun Process spawnShell procNode procName script = do -- cgit v1.2.3