Skip to content

Commit

Permalink
Merge pull request #4240 from bburdette/2259-error-message
Browse files Browse the repository at this point in the history
2259 error message - "auto-call" error
  • Loading branch information
domenkozar committed Jan 15, 2021
2 parents 86a2cee + b327de9 commit 00f99fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,6 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s))
});
}

LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s1))
{
throw TypeError(s, s1);
}

LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2))
{
throw TypeError({
Expand All @@ -686,6 +681,14 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char *
});
}

LocalNoInlineNoReturn(void throwMissingArgumentError(const Pos & pos, const char * s, const string & s1))
{
throw MissingArgumentError({
.hint = hintfmt(s, s1),
.errPos = pos
});
}

LocalNoInline(void addErrorTrace(Error & e, const char * s, const string & s2))
{
e.addTrace(std::nullopt, s, s2);
Expand Down Expand Up @@ -1376,7 +1379,13 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
if (j != args.end()) {
actualArgs->attrs->push_back(*j);
} else if (!i.def) {
throwTypeError("cannot auto-call a function that has an argument without a default value ('%1%')", i.name);
throwMissingArgumentError(i.pos, R"(cannot evaluate a function that has an argument without a value ('%1%')
nix attempted to evaluate a function as a top level expression; in this case it must have its
arguments supplied either by default values, or passed explicitly with --arg or --argstr.
https://nixos.org/manual/nix/stable/#ss-functions)", i.name);

}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/nixexpr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MakeError(ThrownError, AssertionError);
MakeError(Abort, EvalError);
MakeError(TypeError, EvalError);
MakeError(UndefinedVarError, Error);
MakeError(MissingArgumentError, Error);
MakeError(RestrictedPathError, Error);


Expand Down
2 changes: 1 addition & 1 deletion src/libutil/error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace nix {
ErrorInfo structs are sent to the logger as part of an exception, or directly with the
logError or logWarning macros.
See the error-demo.cc program for usage examples.
See libutil/tests/logging.cc for usage examples.
*/

Expand Down

0 comments on commit 00f99fd

Please sign in to comment.