aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd
diff options
context:
space:
mode:
authorBen Burdette <bburdette@protonmail.com>2022-04-07 12:09:47 -0600
committerBen Burdette <bburdette@protonmail.com>2022-04-07 12:09:47 -0600
commitd2ec9b4e15718e42720787140d7825dcbfd73249 (patch)
tree075b67e149c5b4ec0d2973d92d5dd2d00efe18c8 /src/libcmd
parent50b52d51109c430fb2ac69ed5337a6a985e4a486 (diff)
in debugger mode, print the current error when another repl returns.
Diffstat (limited to 'src/libcmd')
-rw-r--r--src/libcmd/repl.cc56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
index 376aa35cd..31d0019d4 100644
--- a/src/libcmd/repl.cc
+++ b/src/libcmd/repl.cc
@@ -203,6 +203,30 @@ namespace {
}
}
+std::ostream& showDebugTrace(std::ostream &out, const DebugTrace &dt)
+{
+ if (dt.is_error)
+ out << ANSI_RED "error: " << ANSI_NORMAL;
+ out << dt.hint.str() << "\n";
+
+ // prefer direct pos, but if noPos then try the expr.
+ auto pos = (*dt.pos ? *dt.pos :
+ (dt.expr.getPos() ? *dt.expr.getPos() : noPos));
+
+ if (pos) {
+ printAtPos(pos, out);
+
+ auto loc = getCodeLines(pos);
+ if (loc.has_value()) {
+ out << "\n";
+ printCodeLines(out, "", pos, *loc);
+ out << "\n";
+ }
+ }
+
+ return out;
+}
+
void NixRepl::mainLoop(const std::vector<std::string> & files)
{
string error = ANSI_RED "error:" ANSI_NORMAL " ";
@@ -251,6 +275,14 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
} else {
printMsg(lvlError, e.msg());
}
+ } catch (EvalError & e) {
+ // in debugger mode, an EvalError should trigger another repl session.
+ // when that session returns the exception will land here. No need to show it again;
+ // show the error for this repl session instead.
+ if (debuggerHook && !this->state->debugTraces.empty())
+ showDebugTrace(std::cout, this->state->debugTraces.front());
+ else
+ printMsg(lvlError, e.msg());
} catch (Error & e) {
printMsg(lvlError, e.msg());
} catch (Interrupted & e) {
@@ -406,30 +438,6 @@ StorePath NixRepl::getDerivationPath(Value & v) {
return drvPath;
}
-std::ostream& showDebugTrace(std::ostream &out, const DebugTrace &dt)
-{
- if (dt.is_error)
- out << ANSI_RED "error: " << ANSI_NORMAL;
- out << dt.hint.str() << "\n";
-
- // prefer direct pos, but if noPos then try the expr.
- auto pos = (*dt.pos ? *dt.pos :
- (dt.expr.getPos() ? *dt.expr.getPos() : noPos));
-
- if (pos) {
- printAtPos(pos, out);
-
- auto loc = getCodeLines(pos);
- if (loc.has_value()) {
- out << "\n";
- printCodeLines(out, "", pos, *loc);
- out << "\n";
- }
- }
-
- return out;
-}
-
void NixRepl::loadDebugTraceEnv(DebugTrace &dt)
{
if (dt.expr.staticenv)