From 2dd61411af903e374566e0cf5d06257ad240662e Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 3 May 2021 14:37:33 -0600 Subject: [PATCH] debugger on autoCallFunction error --- src/libcmd/command.cc | 20 ++++++++++++-------- src/libexpr/eval.cc | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc index d790bb51d..51a071d25 100644 --- a/src/libcmd/command.cc +++ b/src/libcmd/command.cc @@ -79,24 +79,28 @@ ref EvalCommand::getEvalState() return ref(evalState); } */ -EvalCommand::EvalCommand() -{ - addFlag({ - .longName = "debugger", - .description = "start an interactive environment if evaluation fails", - .handler = {&startReplOnEvalErrors, true}, - }); -} // ref EvalCommand::getEvalState() // { // if (!evalState) // evalState = std::make_shared(searchPath, getStore()); // return ref(evalState); // } + + +EvalCommand::EvalCommand() +{ + // std::cout << "EvalCommand::EvalCommand()" << std::endl; + addFlag({ + .longName = "debugger", + .description = "start an interactive environment if evaluation fails", + .handler = {&startReplOnEvalErrors, true}, + }); +} extern std::function & env)> debuggerHook; ref EvalCommand::getEvalState() { + std::cout << " EvalCommand::getEvalState()" << startReplOnEvalErrors << std::endl; if (!evalState) { evalState = std::make_shared(searchPath, getStore()); if (startReplOnEvalErrors) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 37fb6ed18..51feef923 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1398,12 +1398,28 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res) if (j != args.end()) { actualArgs->attrs->push_back(*j); } else if (!i.def) { - throwMissingArgumentError(i.pos, R"(cannot evaluate a function that has an argument without a value ('%1%') + auto error = MissingArgumentError({ + .msg = hintfmt(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'. See -https://nixos.org/manual/nix/stable/#ss-functions.)", i.name); +https://nixos.org/manual/nix/stable/#ss-functions.)", i.name), + .errPos = i.pos + }); + +// 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'. See +// https://nixos.org/manual/nix/stable/#ss-functions.)", i.name); + + if (debuggerHook) + debuggerHook(error, {{"fun", &fun}}); + + throw error; } }