Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for unsupported local target path #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Stack2nix/External/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
6 changes: 3 additions & 3 deletions src/Stack2nix/External/VCS/Git.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)