[Nix#9636] Better "attribute 'x' missing" error message #82

Open
opened 2024-03-16 06:44:49 +00:00 by lix-bot · 1 comment
Member

Upstream-Issue: NixOS/nix#9636

Is your feature request related to a problem? Please describe.
Recently while messing around I encountered an error similar to this:

       error: attribute 'foo' missing

       at /nix/store/a2qc5h0gdpd93yf7l1zg7b05kvd67v0p-source/flake.nix:69:23:

           68|
           69|           bar = foo.outputs.packages.${system}.foo;
             |                 ^
           70|

The solution was quite simple: as the flake I was depending on had the export as default but not by name, changing the final foo to default allowed my build to progress. Unfortunately, due to the attribute and the initial object foo sharing the same name, the caret pointing to the initial foo caused me to think the problem lied with the initial foo and not the attribute.

Describe the solution you'd like
I see two changes that would make this a simpler error to understand:

  1. Move the caret to point to the attribute in question. Had the error read:
       error: attribute 'foo' missing

       at /nix/store/a2qc5h0gdpd93yf7l1zg7b05kvd67v0p-source/flake.nix:69:23:

           68|
           69|           bar = foo.outputs.packages.${system}.foo;
             |                                                ^
           70|

I would not have been confused and would have known where to look immediately

  1. List what the attribute is the attribute of. In my case this might have read something like error: attribute 'foo' of 'foo.outputs.packages."x86_64-linux"' missing. This could also help in more admittedly convoluted cases like the following:
       error: attribute 'foo' of 'foo.bar' missing

       at /nix/store/a2qc5h0gdpd93yf7l1zg7b05kvd67v0p-source/flake.nix:69:23:

           68|
           69|           bar = foo.bar.foo.baz.foo;
             |                 ^
           70|

Note how even though the caret position is unchanged from before, the error message helps differentiate between the initial foo, the attribute foo of bar, and the attribute foo of baz

Thanks for taking the time to read through this!

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/9636 **Is your feature request related to a problem? Please describe.** Recently while messing around I encountered an error similar to this: ``` error: attribute 'foo' missing at /nix/store/a2qc5h0gdpd93yf7l1zg7b05kvd67v0p-source/flake.nix:69:23: 68| 69| bar = foo.outputs.packages.${system}.foo; | ^ 70| ``` The solution was quite simple: as the flake I was depending on had the export as `default` but not by name, changing the final `foo` to `default` allowed my build to progress. Unfortunately, due to the attribute and the initial object `foo` sharing the same name, the caret pointing to the initial `foo` caused me to think the problem lied with the initial foo and not the attribute. **Describe the solution you'd like** I see two changes that would make this a simpler error to understand: 1. Move the caret to point to the attribute in question. Had the error read: ``` error: attribute 'foo' missing at /nix/store/a2qc5h0gdpd93yf7l1zg7b05kvd67v0p-source/flake.nix:69:23: 68| 69| bar = foo.outputs.packages.${system}.foo; | ^ 70| ``` I would not have been confused and would have known where to look immediately 2. List what the attribute is the attribute of. In my case this might have read something like `error: attribute 'foo' of 'foo.outputs.packages."x86_64-linux"' missing`. This could also help in more admittedly convoluted cases like the following: ``` error: attribute 'foo' of 'foo.bar' missing at /nix/store/a2qc5h0gdpd93yf7l1zg7b05kvd67v0p-source/flake.nix:69:23: 68| 69| bar = foo.bar.foo.baz.foo; | ^ 70| ``` Note how even though the caret position is unchanged from before, the error message helps differentiate between the initial `foo`, the attribute `foo` of `bar`, and the attribute `foo` of `baz` Thanks for taking the time to read through this!
lix-bot added the
imported
label 2024-03-16 06:44:49 +00:00
jade added the
ux
label 2024-03-18 16:24:06 +00:00
Owner

@rbt didn't you have a PR for this one?

@rbt didn't you have a PR for this one?
Sign in to join this conversation.
No milestone
No project
No assignees
2 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#82
No description provided.