From 33044b9bd8a564f324af1070540e166041a8f7d7 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 25 Mar 2025 09:58:15 -0700 Subject: [PATCH 1/2] fetchurl: Improve error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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" ] ``` --- pkgs/build-support/fetchurl/default.nix | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index e4a70743334b..9575d98960fe 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -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 From 5aa2e930ec616bcfcdd5ad89d9d8fc54319e2063 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 25 Mar 2025 10:00:54 -0700 Subject: [PATCH 2/2] fetchnuget: improve "multiple hashes" error message --- pkgs/build-support/dotnet/fetchnuget/default.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/dotnet/fetchnuget/default.nix b/pkgs/build-support/dotnet/fetchnuget/default.nix index eca601a746cf..99b70ee4a133 100644 --- a/pkgs/build-support/dotnet/fetchnuget/default.nix +++ b/pkgs/build-support/dotnet/fetchnuget/default.nix @@ -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 ( {