Skip to content

Comments

aliases.nix: always include attr name in error msg#101210

Closed
9999years wants to merge 1 commit intoNixOS:masterfrom
9999years:feature/better-alias-errors
Closed

aliases.nix: always include attr name in error msg#101210
9999years wants to merge 1 commit intoNixOS:masterfrom
9999years:feature/better-alias-errors

Conversation

@9999years
Copy link
Contributor

In pkgs/top-level/aliases.nix, throw was used to make packages that were removed error with a more useful message than attribute 'foobar' missing, at <location>.

However, if the error message doesn't include the package's attribute name, it can be difficult to determine what caused it. For example, here's what building a configuration that referenced ytop looked like recently (see #101098):

$ nixos-rebuild switch
building Nix...
building the system configuration...
error: Abandoned by upstream. Consider switching to bottom instead
(use '--show-trace' to show detailed location information)

Therefore, we modify string values in aliases.nix to prefix Attribute foobar in <nixpkgs> has been removed to the reason message. This makes the removed reasons a bit shorter and provides a place to unilaterally improve these error messages in the future, rather than with one-off changes or large sets of manual fixes.

Built/tested on NixOS.

aliases.nix: errors should include package names

In `pkgs/top-level/aliases.nix`, `throw` was used to make packages that
were removed error with a more useful message than "attribute 'foobar'
missing, at <location>".

However, if the error message doesn't include the package's attribute
name, it can be difficult to determine what caused it. For example,
here's what building a configuration that referenced `ytop` looked like
recently (see NixOS#101098):

```
$ nixos-rebuild switch
building Nix...
building the system configuration...
error: Abandoned by upstream. Consider switching to bottom instead
(use '--show-trace' to show detailed location information)
```

Therefore, we modify string values in `aliases.nix` to prefix `Attribute
foobar in <nixpkgs> has been removed` to the reason message. This makes
the removed reasons a bit shorter and provides a place to unilaterally
improve these error messages in the future, rather than with one-off
changes or large sets of manual fixes.
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Oct 20, 2020
# avoid confusing errors:
# https://github.com/NixOS/nixpkgs/pull/101098
if lib.isString alias then
throw "Attribute ${n} in <nixpkgs> has been removed; ${alias}"
Copy link
Member

Choose a reason for hiding this comment

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

<nixpkgs> might not always exist (e.g. in a flakes-based system). Maybe just s/<nixpkgs>/Nixpkgs/?

@SuperSandro2000
Copy link
Member

I think this would be a great addition but we also would need more people on agreeing if we want this because otherwise @9999years is fixing merge conflicts forever.

@SuperSandro2000 SuperSandro2000 added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 18, 2021
@9999years 9999years closed this Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants