Open michaelsproul opened 9 years ago
These can get very ugly. Right now the evaluator with --show-trace
only output
error: value is a string while a set was expected
and no trace at all. It took me hours before I found where the problem was, among the thousands of (texlive) packages.
Using my latest noisy-nix commits (https://github.com/NixOS/nix/pull/612) the errors show as follows:
$ ~/nix/inst/bin/nix-instantiate . --eval --show-trace --strict -A pkgs.texlive.scheme-full
error: while evaluating the attribute ‘pkgs’ at ~/nixpkgs-test/pkgs/tools/typesetting/tex/texlive-new/default.nix:104:7-104:11:
while evaluating list position ‘10928’:
while evaluating a black hole:
value is a string at ~/nixpkgs-test/pkgs/tools/typesetting/tex/texlive-new/bin.nix:17:15-17:19 while a set was expected at ~/nixpkgs-test/pkgs/tools/typesetting/tex/texlive-new/default.nix:113:15-113:65
$ ~/nix/inst/bin/nix-instantiate --show-trace -E 'with import ./nixos/default.nix { configuration = (a @ {pkgs, ...}: (import /etc/nixos/configuration.nix a) // { environment.systemPackages = [ pkgs.haskellPackages ]; }); }; system'
...
while evaluating the attribute ‘pkgs’ of the derivation ‘system-path’ at ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:38:5-38:9:
while evaluating a black hole at ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:38:5-38:9:
while calling primop toJSON at ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:38:12-41:14:
while evaluating list position ‘250’ at ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:38:12-41:14:
while evaluating the attribute ‘paths’ at ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:39:7-39:12:
while evaluating list position ‘0’ at ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:39:7-39:12:
while calling anonymous function at ~/nixpkgs-test/lib/types.nix:117:14-117:24 from ~/nixpkgs-test/pkgs/build-support/buildenv/default.nix:39:7-39:12:
while evaluating the attribute ‘value’ at ~/nixpkgs-test/lib/types.nix:117:17-117:24:
while evaluating a black hole at ~/nixpkgs-test/lib/types.nix:117:17-117:24:
while calling primop foldl' at ~/nixpkgs-test/lib/modules.nix:314:19-317:43:
while calling anonymous function at ~/nixpkgs-test/lib/modules.nix:314:32-316:96 from ~/nixpkgs-test/lib/modules.nix:314:19-317:43:
while calling ‘check’ at ~/nixpkgs-test/lib/types.nix:97:15-97:49 from ~/nixpkgs-test/lib/modules.nix:315:10-315:30:
while calling ‘isStorePath’ at ~/nixpkgs-test/lib/strings.nix:224:17-224:112 from ~/nixpkgs-test/lib/types.nix:97:36-97:49:
while calling primop substring at ~/nixpkgs-test/lib/strings.nix:224:20-224:55:
while evaluating a black hole at ~/nixpkgs-test/lib/strings.nix:224:20-224:55:
while calling primop toString at ~/nixpkgs-test/lib/strings.nix:224:44-224:54:
cannot coerce a set at (string):1:132-1:152 to a string at ~/nixpkgs-test/lib/strings.nix:224:44-224:54
Maybe someone will want to review them...
@Mathnerd314: That looks quite a bit better.
I get this error, for my configuration.nix
. I have about 250 values in there. :sob:
It's obviously time to tidy up, but until then:
Are there any debugging tactics to track the problematic value down? :pray:
I have use binary search. Comment out half of the file, test, repeat.
Reminds me of:
Nix won't be complete until it has static typing.
:wink:
I marked this as stale due to inactivity. → More info
bump to unstalify
Are there any debugging tactics to track the problematic value down?
do a manual stack trace, by inserting dozens of
{
# TRACE
#someAttr = "some value";
someAttr =
lib.traceSeqN 2 { loc = "line 1234"; someAttr = "some value"; }
"some value"
;
}
... to get a feel for the program flow
--show-trace
more verboseIs your feature request related to a problem? Please describe.
I'm always frustrated when ...
... i have an error in my code, but --show-trace
is too short for debugging
Describe the solution you'd like
--show-trace
should be more verbose,
it should list all function calls, similar to the stack traces in java or javascript
Describe alternatives you've considered
use lib.traceSeq
and friends, to manually locate the error in my code
Additional context
I marked this as stale due to inactivity. → More info
The trace is even worse if you accidentally attempt to access an attset with attrset as a key (e.g., hashes.${stdenv.hostPlatform}
):
let
attr = { foo = "bar"; };
key = {};
in attr.${key}
$ nix-instantiate --version
nix-instantiate (Nix) 2.13.3
$ nix-instantiate --eval bad-trace.nix --show-trace
error: value is a set while a string was expected
at «none»:0: (source not available)
Same with 2.3:
$ nix-instantiate --version
nix-instantiate (Nix) 2.3.16
$ nix-instantiate --eval bad-trace.nix --show-trace
error: value is a set while a string was expected
I found this error quite unhelpful:
The position given for the error is within the NixOS source, so I figured I'd run it again with
--show-trace
.Eventually I traced the error to my use of
ghc
(a set) rather thanghc.ghc784
(a package) inenvironment.systemPackages
. The trace fails to mentionghc
, its contents or its location in the configuration file (/etc/nixos/configuration:64
). Ideally, I would have liked an error like this: