fetchurl: Improve error messages

I recently saw this error message, which required I use the `--debugger`
to locate:

```
error:
       … while evaluating an expression to select 'drvPath' on it
         at «internal»:1:552:
       … while calling the 'derivationStrict' builtin
         at «internal»:1:208:
       (stack trace truncated; use '--show-trace' to show the full trace)

       error: multiple hashes passed to fetchurl
```

This patch improves the error message, and other error messages from
`fetchurl`:

```
error:
       … while evaluating an expression to select 'drvPath' on it
         at «internal»:1:552:
       … while calling the 'derivationStrict' builtin
         at «internal»:1:208:
       (stack trace truncated; use '--show-trace' to show the full trace)

       error: multiple hashes passed to fetchurl: [
         "https://github.com/reorg/pg_repack/archive/refs/tags/ver_1.5.0.tar.gz"
       ]
```
This commit is contained in:
Rebecca Turner
2025-03-25 10:11:28 -07:00
parent b8bdc18c74
commit 33044b9bd8
+14 -7
View File
@@ -119,16 +119,23 @@ in
# Additional packages needed as part of a fetch
nativeBuildInputs ? [ ],
}:
}@args:
let
urls_ =
if urls != [ ] && url == "" then
(if lib.isList urls then urls else throw "`urls` is not a list")
(
if lib.isList urls then urls else throw "`urls` is not a list: ${lib.generators.toPretty { } urls}"
)
else if urls == [ ] && url != "" then
(if lib.isString url then [ url ] else throw "`url` is not a string")
(
if lib.isString url then
[ url ]
else
throw "`url` is not a string: ${lib.generators.toPretty { } urls}"
)
else
throw "fetchurl requires either `url` or `urls` to be set";
throw "fetchurl requires either `url` or `urls` to be set: ${lib.generators.toPretty { } args}";
hash_ =
if
@@ -143,7 +150,7 @@ let
]
) > 1
then
throw "multiple hashes passed to fetchurl"
throw "multiple hashes passed to fetchurl: ${lib.generators.toPretty { } urls_}"
else
if hash != "" then
@@ -155,7 +162,7 @@ let
if outputHashAlgo != "" then
{ inherit outputHashAlgo outputHash; }
else
throw "fetchurl was passed outputHash without outputHashAlgo"
throw "fetchurl was passed outputHash without outputHashAlgo: ${lib.generators.toPretty { } urls_}"
else if sha512 != "" then
{
outputHashAlgo = "sha512";
@@ -177,7 +184,7 @@ let
outputHash = "";
}
else
throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}";
throw "fetchurl requires a hash for fixed-output derivation: ${lib.generators.toPretty urls_}";
in
assert