[Nix#9865] Provide suggestions in error messages for getAttr #64

Open
opened 2024-03-16 06:44:43 +00:00 by lix-bot · 0 comments
Member

Upstream-Issue: NixOS/nix#9865

Is your feature request related to a problem? Please describe.

Errors involving installables or names explicitly lexically appearing in Nix code, including using the CLI for non-flakes purposes, provide name suggestions for attributes:

 » nix eval -f '<nixpkgs>' lib.f1x                                           
error: attribute 'f1x' in selection path 'lib.f1x' not found
       Did you mean one of fix, fix' or max?

However, this is not the case in dynamically getting attributes, which can be annoying when the offending string came from the user somehow.

co/nix » ./outputs/out/bin/nix --extra-experimental-features 'nix-command' eval -f '<nixpkgs>' --apply 'x: with x {}; builtins.getAttr "f1x" lib'
error:
       … while calling the 'getAttr' builtin
         at «string»:1:15:
            1| x: with x {}; builtins.getAttr "f1x" lib
             |               ^

       … in the attribute set under consideration

       error: attribute 'f1x' missing

Describe the solution you'd like

I would like to have getAttr try to provide suggestions for the intended attributes.

Describe alternatives you've considered

Well, we can simply make it appear lexically in Nix code, which would make everyone supremely happy I anticipate :)

nix-repl> import (builtins.toFile "test.nix" "x: x.f1x") lib 
error: attribute 'f1x' missing

       at /nix/store/nlcfifyf5b7vizi722dsjvzshvpfd1d7-test.nix:1:4:

            1| x: x.f1x
             |    ^
       Did you mean one of fix, fix' or max?

Additional context

Tested in 1c260fa6d1f47d83954792771d0614db163cc3bc.

Priorities

Add 👍 to issues you find important.

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/9865 **Is your feature request related to a problem? Please describe.** Errors involving installables or names explicitly lexically appearing in Nix code, including using the CLI for non-flakes purposes, provide name suggestions for attributes: ``` » nix eval -f '<nixpkgs>' lib.f1x error: attribute 'f1x' in selection path 'lib.f1x' not found Did you mean one of fix, fix' or max? ``` However, this is not the case in dynamically getting attributes, which can be annoying when the offending string came from the user somehow. ``` co/nix » ./outputs/out/bin/nix --extra-experimental-features 'nix-command' eval -f '<nixpkgs>' --apply 'x: with x {}; builtins.getAttr "f1x" lib' error: … while calling the 'getAttr' builtin at «string»:1:15: 1| x: with x {}; builtins.getAttr "f1x" lib | ^ … in the attribute set under consideration error: attribute 'f1x' missing ``` **Describe the solution you'd like** I would like to have getAttr try to provide suggestions for the intended attributes. **Describe alternatives you've considered** Well, we can simply make it appear lexically in Nix code, which would make everyone supremely happy I anticipate :) ``` nix-repl> import (builtins.toFile "test.nix" "x: x.f1x") lib error: attribute 'f1x' missing at /nix/store/nlcfifyf5b7vizi722dsjvzshvpfd1d7-test.nix:1:4: 1| x: x.f1x | ^ Did you mean one of fix, fix' or max? ``` **Additional context** Tested in 1c260fa6d1f47d83954792771d0614db163cc3bc. **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
imported
label 2024-03-16 06:44:43 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#64
No description provided.