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

2259 error message - "auto-call" error #4240

Merged
merged 8 commits into from
Jan 15, 2021

Conversation

bburdette
Copy link
Contributor

revised this "auto-call" error which I've found to be somewhat inscrutable in the past. This is intended to address (in part) issue #2259.

  • UndefinedVarError seemed more appropriate than TypeError
  • added Pos
  • big error message with examples.
  • link to a nix pill for further explanation.

Current output is like this:

image

Revised error output is like so:

image

This reflect my perhaps imperfect understanding of autoCall, feedback on that is welcome.

@bburdette bburdette changed the title 2259 error message [WIP] 2259 error message - "auto-call" error Nov 10, 2020
@bburdette
Copy link
Contributor Author

Some slight changes:

image

@edolstra
Copy link
Member

I think very long error messages should be avoided since then we just end up duplicating the manual. The error message can also get out of date, for instance it talks about nix-build and a specific (non-flake) style of importing Nixpkgs. It may also lead the user astray that we're talking about callPackage but the error message might have nothing to do with callPackage.

It's probably better to have a shorter message that links to the manual for more information (not Nix pills which are not an authoritative reference for Nix).

throwTypeError("cannot auto-call a function that has an argument without a default value ('%1%')", i.name);
throwUndefinedVarError(i.pos, R"(cannot auto-call a function that has an argument without a default value ('%1%')

An 'auto-call' is when a nix expression is evaluated without any external arguments.
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. An auto-call is when a top-level function is called with external arguments or with default values if no matching argument is provided.

It's probably better to say something like `you need to pass "--arg %1% ...' or '--argstr %1% ...'".

Copy link
Member

Choose a reason for hiding this comment

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

UndefinedVarError is probably misleading. There is no undefined variable, just a missing argument.

@bburdette
Copy link
Contributor Author

Thanks for the feedback!

  • pared down the error message
  • error is more generic rather than callPackage centric
  • docs link goes to function reference in the manual.
  • added a MissingArgumentError rather than using TypeError or UndefinedVarError.

Here's the result:

image

@domenkozar domenkozar merged commit 00f99fd into NixOS:master Jan 15, 2021
@bburdette
Copy link
Contributor Author

Thanks for the merge!

thufschmitt added a commit that referenced this pull request Feb 22, 2021
The PR #4240 changed messag of the error that was thrown when an auto-called
function was missing an argument.
However this change also changed the type of the error, from `EvalError`
to a new `MissingArgumentError`. This broke hydra which was relying on
an `EvalError` being thrown.

Make `MissingArgumentError` a subclass of `EvalError` to un-break hydra.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants