Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass positions when evaluating #9555

Merged
merged 2 commits into from Dec 9, 2023
Merged

Conversation

9999years
Copy link
Contributor

@9999years 9999years commented Dec 7, 2023

Motivation

This includes position information in more places, making debugging easier. This removes «none»:0: (source not available) from error messages in many cases.

Context

Final fix for #561 (comment).

Before:

error:
       … while evaluating an attribute name

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

       error: value is a set while a string was expected

After:

error:
       … while evaluating an attribute name

         at /Users/wiggles/nix/bad.nix:4:11:

            3|   key = {};
            4| in attr.${key}
             |           ^
            5|

       error: value is a set while a string was expected

Before:

$ nix-instantiate --show-trace --eval tests/functional/lang/eval-fail-call-primop.nix
error:
       … while calling the 'length' builtin

         at /Users/wiggles/nix/tests/functional/lang/eval-fail-call-primop.nix:1:1:

            1| builtins.length 1
             | ^
            2|

       … while evaluating the first argument passed to builtins.length

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

       error: value is an integer while a list was expected

After:

error:
       … while calling the 'length' builtin

         at /Users/wiggles/nix/tests/functional/lang/eval-fail-call-primop.nix:1:1:

            1| builtins.length 1
             | ^
            2|

       … while evaluating the first argument passed to builtins.length

       error: value is an integer while a list was expected

Before:

$ nix-instantiate --show-trace --eval tests/functional/lang/eval-fail-not-throws.nix
error:
       … in the argument of the not operator

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

       … while calling the 'throw' builtin

         at /Users/wiggles/nix/tests/functional/lang/eval-fail-not-throws.nix:1:4:

            1| ! (throw "uh oh!")
             |    ^
            2|

       error: uh oh!

After:

error:
       … in the argument of the not operator

         at /Users/wiggles/nix/tests/functional/lang/eval-fail-not-throws.nix:1:4:

            1| ! (throw "uh oh!")
             |    ^
            2|

       … while calling the 'throw' builtin

         at /Users/wiggles/nix/tests/functional/lang/eval-fail-not-throws.nix:1:4:

            1| ! (throw "uh oh!")
             |    ^
            2|

       error: uh oh!

Priorities

Add 👍 to pull requests you find important.

@roberth
Copy link
Member

roberth commented Dec 7, 2023

Could you turn the example into a test case?
You could add it as tests/functional/lang/eval-fail-<name>.nix and then when you run make tests/functional/lang.sh.test the error message will help you along.

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Dec 7, 2023
@9999years
Copy link
Contributor Author

Could you turn the example into a test case?

Done! (I finished this at the end of the day and didn't have time to write tests.)

This includes position information in more places, making debugging
easier.

Before:

```
$ nix-instantiate --show-trace --eval tests/functional/lang/eval-fail-using-set-as-attr-name.nix
error:
       … while evaluating an attribute name

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

       error: value is a set while a string was expected
```

After:

```
error:
       … while evaluating an attribute name

         at /pwd/lang/eval-fail-using-set-as-attr-name.nix:5:10:

            4| in
            5|   attr.${key}
             |          ^
            6|

       error: value is a set while a string was expected
```
Comment on lines 23 to 24

at «none»:0: (source not available)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

It didn't do that anymore since 2.19.

You may set _NIX_DEVELOPER_SHOW_UNKNOWN_LOCATIONS=1 to show the missing positions once more.

@roberth
Copy link
Member

roberth commented Dec 9, 2023

Awesome, thanks!

@roberth roberth merged commit c8458bd into NixOS:master Dec 9, 2023
8 checks passed
@9999years 9999years deleted the positions-in-errors branch January 4, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants