From 3629b0585aaf13f7d25510c55ca06611cb2135af Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Wed, 1 Jul 2020 11:49:01 -0600 Subject: [PATCH] don't include errpos for addErrorContext --- src/libexpr/primops.cc | 3 +-- src/libutil/error.cc | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 4cc3718e3..dec917b38 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -471,8 +471,7 @@ static void prim_addErrorContext(EvalState & state, const Pos & pos, Value * * a v = *args[1]; } catch (Error & e) { PathSet context; - // TODO: is this right, include this pos?? Test it. esp with LOC. - e.addTrace(pos, "%1%", state.coerceToString(pos, *args[0], context)); + e.addTrace(std::nullopt, state.coerceToString(pos, *args[0], context)); throw; } } diff --git a/src/libutil/error.cc b/src/libutil/error.cc index 78e2a5ea2..3a9b924f2 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -305,7 +305,7 @@ std::ostream& showErrorInfo(std::ostream &out, const ErrorInfo &einfo, bool show nl = true; } - if (einfo.errPos.has_value()) { + if (einfo.errPos.has_value() && (*einfo.errPos)) { auto loc = getCodeLines(*einfo.errPos); // lines of code. @@ -359,9 +359,10 @@ std::ostream& showErrorInfo(std::ostream &out, const ErrorInfo &einfo, bool show out << ANSI_BLUE << "trace: " << ANSI_NORMAL << iter->hint.str(); nl = true; - auto pos = *iter->pos; - if (pos) { + if (*iter->pos) { + auto pos = iter->pos.value(); out << std::endl << prefix; + printAtPos(prefix, pos, out); auto loc = getCodeLines(pos); if (loc.has_value())