diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 2345a5e3c..9ec32a0de 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -826,7 +826,7 @@ static void prim_addErrorContext(EvalState & state, const PosIdx pos, Value * * auto message = state.coerceToString(pos, *args[0], context, "while evaluating the error message passed to builtins.addErrorContext", false, false).toOwned(); - e.addTrace(nullptr, HintFmt(message), TraceKind::Custom); + e.addTrace(nullptr, HintFmt(message), TracePrint::Always); throw; } } diff --git a/src/libutil/error.cc b/src/libutil/error.cc index e9c6437cd..036e19e26 100644 --- a/src/libutil/error.cc +++ b/src/libutil/error.cc @@ -11,9 +11,9 @@ namespace nix { -void BaseError::addTrace(std::shared_ptr && e, HintFmt hint, TraceKind kind) +void BaseError::addTrace(std::shared_ptr && e, HintFmt hint, TracePrint print) { - err.traces.push_front(Trace { .pos = std::move(e), .hint = hint, .kind = kind }); + err.traces.push_front(Trace { .pos = std::move(e), .hint = hint, .print = print }); } void throwExceptionSelfCheck(){ @@ -388,7 +388,7 @@ std::ostream & showErrorInfo(std::ostream & out, const ErrorInfo & einfo, bool s truncate = true; } - if (!truncate || trace.kind == TraceKind::Custom) { + if (!truncate || trace.print == TracePrint::Always) { if (tracesSeen.count(trace)) { skippedTraces.push_back(trace); diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 6701a75b3..d23625a54 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -61,16 +61,22 @@ void printCodeLines(std::ostream & out, const Pos & errPos, const LinesOfCode & loc); -enum struct TraceKind { - Other, - /** Produced by builtins.addErrorContext. Always printed. */ - Custom, +/** + * When a stack frame is printed. + */ +enum struct TracePrint { + /** + * The default behavior; always printed when `--show-trace` is set. + */ + Default, + /** Always printed. Produced by `builtins.addErrorContext`. */ + Always, }; struct Trace { std::shared_ptr pos; HintFmt hint; - TraceKind kind = TraceKind::Other; + TracePrint print = TracePrint::Default; }; inline bool operator<(const Trace& lhs, const Trace& rhs); @@ -168,7 +174,7 @@ public: addTrace(std::move(e), HintFmt(std::string(fs), args...)); } - void addTrace(std::shared_ptr && e, HintFmt hint, TraceKind kind = TraceKind::Other); + void addTrace(std::shared_ptr && e, HintFmt hint, TracePrint print = TracePrint::Default); bool hasTrace() const { return !err.traces.empty(); }