fetchurl: improve error messages (#393136)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
{
|
||||
lib,
|
||||
fetchurl,
|
||||
buildDotnetPackage,
|
||||
unzip,
|
||||
@@ -14,10 +15,12 @@ attrs@{
|
||||
...
|
||||
}:
|
||||
if md5 != "" then
|
||||
throw "fetchnuget does not support md5 anymore, please use 'hash' attribute with SRI hash"
|
||||
throw "fetchnuget does not support md5 anymore, please use 'hash' attribute with SRI hash: ${
|
||||
lib.generators.toPretty { } attrs
|
||||
}"
|
||||
# This is also detected in fetchurl, but we just throw here to avoid confusion
|
||||
else if (sha256 != "" && hash != "") then
|
||||
throw "multiple hashes passed to fetchNuGet"
|
||||
throw "multiple hashes passed to fetchNuGet: ${lib.generators.toPretty { } url}"
|
||||
else
|
||||
buildDotnetPackage (
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user