diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index d3f203748..4882199f4 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -1206,7 +1206,7 @@ Value EvalState::callFunction(Value & fun, std::span args, const PosIdx p } catch (ThrownError & e) { // Distinguish between an error that simply happened while "throw" // was being evaluated and an explicit thrown error. - if (fn->name == "throw") { + if (fn->name == "throw" && !e.hasTrace()) { e.addTrace(ctx.positions[pos], "caused by explicit %s", "throw"); } else { e.addTrace(ctx.positions[pos], "while calling the '%s' builtin", fn->name); diff --git a/tests/functional2/lang/select-err/eval-fail-2.err.exp b/tests/functional2/lang/select-err/eval-fail-2.err.exp new file mode 100644 index 000000000..6ed4d7594 --- /dev/null +++ b/tests/functional2/lang/select-err/eval-fail-2.err.exp @@ -0,0 +1,23 @@ +error: + … while calling the 'throw' builtin + at /pwd/in.nix:6:1: + 5| in + 6| throw set.inner + | ^ + 7| + + … while evaluating the attribute 'inner' + at /pwd/in.nix:3:5: + 2| set = { + 3| inner = throw "nested throw"; + | ^ + 4| }; + + … caused by explicit throw + at /pwd/in.nix:3:13: + 2| set = { + 3| inner = throw "nested throw"; + | ^ + 4| }; + + error: nested throw diff --git a/tests/functional2/lang/select-err/in-2.nix b/tests/functional2/lang/select-err/in-2.nix new file mode 100644 index 000000000..2d4319ed2 --- /dev/null +++ b/tests/functional2/lang/select-err/in-2.nix @@ -0,0 +1,6 @@ +let + set = { + inner = throw "nested throw"; + }; +in +throw set.inner