Handle ExitCodeException in wrapErr (#2415)

This is thrown by typed-process when the child process exits with a
non-zero exitcode.

fixes #2414
This commit is contained in:
Moritz Kiefer 2019-08-06 10:49:25 +02:00 committed by mergify[bot]
parent e0ced61770
commit 656d8f4a19
2 changed files with 3 additions and 0 deletions

View File

@ -63,6 +63,7 @@ da_haskell_library(
"text",
"time",
"tls",
"typed-process",
"unix-compat",
"utf8-string",
"yaml",

View File

@ -14,6 +14,7 @@ import Control.Exception.Safe
import Control.Applicative
import Control.Monad.Extra
import Data.Either.Extra
import System.Process.Typed (ExitCodeException(..))
-- | Throw an assistant error.
throwErr :: Text -> IO a
@ -24,6 +25,7 @@ throwErr msg = throwIO (assistantError msg)
wrapErr :: Text -> IO a -> IO a
wrapErr ctx m = m `catches`
[ Handler $ throwIO @IO @ExitCode
, Handler $ \(ExitCodeException{eceExitCode}) -> exitWith eceExitCode
, Handler $ throwIO . addErrorContext
, Handler $ throwIO . wrapException
]