1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 11:11:03 -04:00

show expr pos if DebugTrace one is noPos

This commit is contained in:
Ben Burdette 2022-04-06 19:08:29 -06:00
parent f41c18b221
commit 5cfd038bd8
2 changed files with 6 additions and 4 deletions

View file

@ -129,7 +129,7 @@ ref<EvalState> EvalCommand::getEvalState()
new DebugTraceStacker( new DebugTraceStacker(
*evalState, *evalState,
DebugTrace DebugTrace
{.pos = *expr.getPos(), {.pos = (error->info().errPos ? *error->info().errPos : *expr.getPos()),
.expr = expr, .expr = expr,
.env = env, .env = env,
.hint = error->info().msg, .hint = error->info().msg,

View file

@ -412,9 +412,11 @@ std::ostream& showDebugTrace(std::ostream &out, const DebugTrace &dt)
out << ANSI_RED "error: " << ANSI_NORMAL; out << ANSI_RED "error: " << ANSI_NORMAL;
out << dt.hint.str() << "\n"; out << dt.hint.str() << "\n";
if (dt.pos.has_value() && (*dt.pos)) { // prefer direct pos, but if noPos then try the expr.
auto pos = dt.pos.value(); auto pos = (*dt.pos ? *dt.pos :
out << "\n"; (dt.expr.getPos() ? *dt.expr.getPos() : noPos));
if (pos) {
printAtPos(pos, out); printAtPos(pos, out);
auto loc = getCodeLines(pos); auto loc = getCodeLines(pos);