Skip to content

Commit

Permalink
missing argument error
Browse files Browse the repository at this point in the history
  • Loading branch information
bburdette committed Nov 11, 2020
1 parent 7d90370 commit 3edfe60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,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 @@ -1365,15 +1373,15 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
if (j != args.end()) {
actualArgs->attrs->push_back(*j);
} else if (!i.def) {
throwUndefinedVarError(i.pos, R"(cannot auto-call a function that has an argument without a default value ('%1%')
throwMissingArgumentError(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.
If that nix expression is a function, and that function's arguments all have default
values, then all is well.
But if the function arguments don't have default values, evaluation fails.
The classic case for this error is evaluating a nix file with nix-build that expects
The classic case for this error is evaluating a nix file that expects
to be evaluated by callPackage.
# in 'callPackage' format: expression is a function that takes an argument 'stdenv'.
# callPackage would implicitly pull 'stdenv' from nixpkgs, then call this function.
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

0 comments on commit 3edfe60

Please sign in to comment.