aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burdette <bburdette@protonmail.com>2022-04-06 19:08:29 -0600
committerBen Burdette <bburdette@protonmail.com>2022-04-06 19:08:29 -0600
commit5cfd038bd8bcd65c45f08f6c3665cd49e6643714 (patch)
tree217d909a97cfec7d8d44928e5123fab006e10c2d
parentf41c18b2210ac36743f03ea218860b7941f4264e (diff)
show expr pos if DebugTrace one is noPos
-rw-r--r--src/libcmd/command.cc2
-rw-r--r--src/libcmd/repl.cc8
2 files changed, 6 insertions, 4 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc
index 34535802f..cc353cbb4 100644
--- a/src/libcmd/command.cc
+++ b/src/libcmd/command.cc
@@ -129,7 +129,7 @@ ref<EvalState> EvalCommand::getEvalState()
new DebugTraceStacker(
*evalState,
DebugTrace
- {.pos = *expr.getPos(),
+ {.pos = (error->info().errPos ? *error->info().errPos : *expr.getPos()),
.expr = expr,
.env = env,
.hint = error->info().msg,
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
index 5de4cdf76..416635f16 100644
--- a/src/libcmd/repl.cc
+++ b/src/libcmd/repl.cc
@@ -412,9 +412,11 @@ std::ostream& showDebugTrace(std::ostream &out, const DebugTrace &dt)
out << ANSI_RED "error: " << ANSI_NORMAL;
out << dt.hint.str() << "\n";
- if (dt.pos.has_value() && (*dt.pos)) {
- auto pos = dt.pos.value();
- out << "\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);