[Nix#8721] Traces from errors in functions don't show the actual error location #130

Closed
opened 2024-03-16 06:45:04 +00:00 by lix-bot · 2 comments
Member

Upstream-Issue: NixOS/nix#8721

Describe the bug

It seems that at least when nested in functions, the actual error location, by far the most important piece of information, is not shown in the trace.

This work is sponsored by Antithesis

Steps To Reproduce

Here's just builtins.length "test", an obvious type error:

$ nix-instantiate --eval --show-trace --expr 'builtins.length "test"'
error:
       … while calling the 'length' builtin

         at «string»:1:1:

            1| builtins.length "test"
             | ^

       … while evaluating the first argument passed to builtins.length

         at «none»:0: (source not available)

       error: value is a string while a list was expected

Notice how it correctly shows the error occurring "while calling the 'length' builtin", along with the precise location of the builtin.

But now let's wrap it in a function:

$ nix-instantiate --eval --show-trace --expr 'let f = v: builtins.length v; in f "test"'
error:
       … from call site

         at «string»:1:34:

            1| let f = v: builtins.length v; in f "test"
             |                                  ^

       … while calling 'f'

         at «string»:1:9:

            1| let f = v: builtins.length v; in f "test"
             |         ^

       error: value is a string while a list was expected

Now the trace on the builtin isn't there anymore, the trace stops at the enclosing function call and doesn't show anything more detailed.

This makes it really hard to debug larger functions.

Expected behavior

The exact location of where the error occurred should be shown.

nix-env --version output

nix-env (Nix) 2.15.1

Additional context

Priorities

Add 👍 to issues you find important.

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/8721 **Describe the bug** It seems that at least when nested in functions, the actual error location, by far the most important piece of information, is not shown in the trace. This work is sponsored by [Antithesis](https://antithesis.com/) :sparkles: **Steps To Reproduce** Here's just `builtins.length "test"`, an obvious type error: ``` $ nix-instantiate --eval --show-trace --expr 'builtins.length "test"' error: … while calling the 'length' builtin at «string»:1:1: 1| builtins.length "test" | ^ … while evaluating the first argument passed to builtins.length at «none»:0: (source not available) error: value is a string while a list was expected ``` Notice how it correctly shows the error occurring "while calling the 'length' builtin", along with the precise location of the builtin. But now let's wrap it in a function: ``` $ nix-instantiate --eval --show-trace --expr 'let f = v: builtins.length v; in f "test"' error: … from call site at «string»:1:34: 1| let f = v: builtins.length v; in f "test" | ^ … while calling 'f' at «string»:1:9: 1| let f = v: builtins.length v; in f "test" | ^ error: value is a string while a list was expected ``` Now the trace on the builtin isn't there anymore, the trace stops at the enclosing function call and doesn't show anything more detailed. This makes it really hard to debug larger functions. **Expected behavior** The exact location of where the error occurred should be shown. **`nix-env --version` output** nix-env (Nix) 2.15.1 **Additional context** **Priorities** Add :+1: to [issues you find important](https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc).
lix-bot added the
bug
imported
labels 2024-03-16 06:45:04 +00:00
jade added the
release-blocker
label 2024-03-24 03:34:11 +00:00
jade added this to the v2.90 milestone 2024-03-24 03:34:16 +00:00
Owner

Marking as release blocker because this sucks, but we can revisit that decision later.

Marking as release blocker because this sucks, but we can revisit that decision later.
jade added this to the Release engineering project 2024-03-24 06:24:58 +00:00
Owner

this is fixed on main:

$ git rev-parse HEAD
531b8d0ab846966795524951dd260d403d8a0d04
$ nix build 
$ nix --version
nix (Nix) 2.90.0-lix
$ nix-instantiate --eval --show-trace --expr 'let f = v: builtins.length v; in f "test"'       
error:
       … from call site
         at «string»:1:34:
            1| let f = v: builtins.length v; in f "test"
             |                                  ^

       … while calling 'f'
         at «string»:1:9:
            1| let f = v: builtins.length v; in f "test"
             |         ^

       error: value is a string while a list was expected
$ result/bin/nix --version
nix (Lix, like Nix) 2.90.0
$ result/bin/nix-instantiate --eval --show-trace --expr 'let f = v: builtins.length v; in f "test"'
error:
       … from call site
         at «string»:1:34:
            1| let f = v: builtins.length v; in f "test"
             |                                  ^

       … while calling 'f'
         at «string»:1:9:
            1| let f = v: builtins.length v; in f "test"
             |         ^

       … while calling the 'length' builtin
         at «string»:1:12:
            1| let f = v: builtins.length v; in f "test"
             |            ^

       … while evaluating the first argument passed to builtins.length

       error: expected a list but found a string: "test"
this is fixed on main: ```ShellSession $ git rev-parse HEAD 531b8d0ab846966795524951dd260d403d8a0d04 $ nix build $ nix --version nix (Nix) 2.90.0-lix $ nix-instantiate --eval --show-trace --expr 'let f = v: builtins.length v; in f "test"' error: … from call site at «string»:1:34: 1| let f = v: builtins.length v; in f "test" | ^ … while calling 'f' at «string»:1:9: 1| let f = v: builtins.length v; in f "test" | ^ error: value is a string while a list was expected $ result/bin/nix --version nix (Lix, like Nix) 2.90.0 $ result/bin/nix-instantiate --eval --show-trace --expr 'let f = v: builtins.length v; in f "test"' error: … from call site at «string»:1:34: 1| let f = v: builtins.length v; in f "test" | ^ … while calling 'f' at «string»:1:9: 1| let f = v: builtins.length v; in f "test" | ^ … while calling the 'length' builtin at «string»:1:12: 1| let f = v: builtins.length v; in f "test" | ^ … while evaluating the first argument passed to builtins.length error: expected a list but found a string: "test" ```
Sign in to join this conversation.
No milestone
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#130
No description provided.