From a2b1e4ec9810993778d1d2cc8da133c692f69262 Mon Sep 17 00:00:00 2001 From: Martin Lavoie Date: Sun, 26 Sep 2021 11:47:43 +0200 Subject: [PATCH] Better error message when nix-prefetch-url return an error 404 close nmattia/niv#129 close nmattia/niv#309 close nmattia/niv#330 --- src/Niv/GitHub/Cmd.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Niv/GitHub/Cmd.hs b/src/Niv/GitHub/Cmd.hs index d04806a..43f7bd7 100644 --- a/src/Niv/GitHub/Cmd.hs +++ b/src/Niv/GitHub/Cmd.hs @@ -11,6 +11,7 @@ module Niv.GitHub.Cmd where import Control.Applicative +import Control.Monad import Data.Aeson ((.=)) import qualified Data.Aeson as Aeson import Data.Bifunctor @@ -160,7 +161,10 @@ nixPrefetchURL unpack packageName (T.unpack -> url) = do (exitCode, sout, serr) <- runNixPrefetch case (exitCode, lines sout) of (ExitSuccess, l : _) -> pure $ T.pack l - _ -> abortNixPrefetchExpectedOutput (T.pack <$> args) (T.pack sout) (T.pack serr) + _ -> do + let tserr = T.pack serr + checkNixPrefetchUrlNotFound (T.pack url) tserr + abortNixPrefetchExpectedOutput (T.pack <$> args) (T.pack sout) tserr where args = (if unpack then ["--unpack"] else []) <> [url, "--name", sanitizeName basename <> "-src"] runNixPrefetch = readProcessWithExitCode "nix-prefetch-url" args "" @@ -172,6 +176,16 @@ nixPrefetchURL unpack packageName (T.unpack -> url) = do -- (note: we assume they don't begin with a period) isOk = \c -> isAlphaNum c || T.any (c ==) "+-._?=" +checkNixPrefetchUrlNotFound :: T.Text -> T.Text -> IO () +checkNixPrefetchUrlNotFound url serr = do + guard ("HTTP error 404" `T.isInfixOf` serr) + abort $ T.unlines + [ "The url '" <> url <> "' was not found by 'nix-prefetch-url'." + , "Changing your source's template or attributes may help you resolve the situation." + , "For further help, you can read the niv readme at https://github.com/nmattia/niv" + , "or open an ticket at https://github.com/nmattia/niv/issues/new." + ] + abortNixPrefetchExpectedOutput :: [T.Text] -> T.Text -> T.Text -> IO a abortNixPrefetchExpectedOutput args sout serr = abort $