From 981c3090570ca3b9c75098ab482049cc3b4dc2b0 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 24 Mar 2024 00:04:30 +0100 Subject: [PATCH] Remove trace item: while calling the 'addErrorContext' builtin --- src/libexpr/eval.cc | 6 ++++-- src/libexpr/eval.hh | 7 +++++++ src/libexpr/primops.cc | 2 ++ .../lang/eval-fail-addErrorContext-example.err.exp | 14 -------------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 5e2f71649..86251adf7 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1665,7 +1665,8 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & try { fn->fun(*this, vCur.determinePos(noPos), args, vCur); } catch (Error & e) { - addErrorTrace(e, pos, "while calling the '%1%' builtin", fn->name); + if (fn->addTrace) + addErrorTrace(e, pos, "while calling the '%1%' builtin", fn->name); throw; } @@ -1713,7 +1714,8 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & // so the debugger allows to inspect the wrong parameters passed to the builtin. fn->fun(*this, vCur.determinePos(noPos), vArgs, vCur); } catch (Error & e) { - addErrorTrace(e, pos, "while calling the '%1%' builtin", fn->name); + if (fn->addTrace) + addErrorTrace(e, pos, "while calling the '%1%' builtin", fn->name); throw; } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index f15d19653..f45971290 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -69,6 +69,13 @@ struct PrimOp */ const char * doc = nullptr; + /** + * Add a trace item, `while calling the '' builtin` + * + * This is used to remove the redundant item for `builtins.addErrorContext`. + */ + bool addTrace = true; + /** * Implementation of the primop. */ diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 8a188e0c4..2345a5e3c 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -834,6 +834,8 @@ static void prim_addErrorContext(EvalState & state, const PosIdx pos, Value * * static RegisterPrimOp primop_addErrorContext(PrimOp { .name = "__addErrorContext", .arity = 2, + // The normal trace item is redundant + .addTrace = false, .fun = prim_addErrorContext, }); diff --git a/tests/functional/lang/eval-fail-addErrorContext-example.err.exp b/tests/functional/lang/eval-fail-addErrorContext-example.err.exp index 3d390cd37..4fad8f5c8 100644 --- a/tests/functional/lang/eval-fail-addErrorContext-example.err.exp +++ b/tests/functional/lang/eval-fail-addErrorContext-example.err.exp @@ -1,20 +1,6 @@ error: - … while calling the 'addErrorContext' builtin - at /pwd/lang/eval-fail-addErrorContext-example.nix:6:7: - 5| else - 6| builtins.addErrorContext - | ^ - 7| "while counting down; n = ${toString n}" - … while counting down; n = 10 - … while calling the 'addErrorContext' builtin - at /pwd/lang/eval-fail-addErrorContext-example.nix:6:7: - 5| else - 6| builtins.addErrorContext - | ^ - 7| "while counting down; n = ${toString n}" - … while counting down; n = 9 … while counting down; n = 8