diff --git a/src/Stack2nix/External/Util.hs b/src/Stack2nix/External/Util.hs index c3543f3..c58a662 100644 --- a/src/Stack2nix/External/Util.hs +++ b/src/Stack2nix/External/Util.hs @@ -16,9 +16,13 @@ runCmdFrom dir prog args = runCmd :: String -> [String] -> IO (ExitCode, String, String) runCmd prog args = getCurrentDirectory >>= (\d -> runCmdFrom d prog args) -failHard :: (ExitCode, String, String) -> IO (ExitCode, String, String) -failHard r@(ExitSuccess, _, _) = pure r -failHard (ExitFailure code, _, stderr) = +failHardWith :: String -> (ExitCode, String, String) -> IO (ExitCode, String, String) +failHardWith _msg r@(ExitSuccess, _, _) = pure r +failHardWith msg (ExitFailure code, _, stderr) = error $ unlines [ "Failed with exit code " <> show code <> "..." - , show stderr + , stderr + , msg ] + +failHard :: (ExitCode, String, String) -> IO (ExitCode, String, String) +failHard = failHardWith "" diff --git a/src/Stack2nix/External/VCS/Git.hs b/src/Stack2nix/External/VCS/Git.hs index 639bd79..b8ed678 100644 --- a/src/Stack2nix/External/VCS/Git.hs +++ b/src/Stack2nix/External/VCS/Git.hs @@ -3,7 +3,7 @@ module Stack2nix.External.VCS.Git , git ) where -import Stack2nix.External.Util (failHard, runCmd, runCmdFrom) +import Stack2nix.External.Util (failHardWith, runCmd, runCmdFrom) import System.Exit (ExitCode (..)) data Command = OutsideRepo ExternalCmd @@ -23,8 +23,8 @@ git (InsideRepo dir cmd) = runInternal dir cmd runExternal :: ExternalCmd -> IO (ExitCode, String, String) runExternal (Clone uri dir) = - runCmd exe ["clone", uri, dir] >>= failHard + runCmd exe ["clone", uri, dir] >>= failHardWith ("git: expected " ++ uri ++ " to be a repository, but it can't be cloned") runInternal :: FilePath -> InternalCmd -> IO (ExitCode, String, String) runInternal repoDir (Checkout ref) = - runCmdFrom repoDir exe ["checkout", ref] >>= failHard + runCmdFrom repoDir exe ["checkout", ref] >>= failHardWith ("git: failed to checkout revision " ++ ref)