diff --git a/doc/manual/rl-next/error-message-improvements.md b/doc/manual/rl-next/error-message-improvements.md new file mode 100644 index 000000000..4fb6f5c4d --- /dev/null +++ b/doc/manual/rl-next/error-message-improvements.md @@ -0,0 +1,9 @@ +--- +synopsis: Small error message improvements +issues: [] +cls: [2185] +category: Improvements +credits: [piegames] +--- + +Failed asserts don't print the failed assertion expression anymore in the error message. That code was buggy and the information was redundant anyways, given that the error position already more accurately shows what exactly failed. diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 5dd4b6beb..d0a1a569c 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -1827,9 +1827,10 @@ void ExprIf::eval(EvalState & state, Env & env, Value & v) void ExprAssert::eval(EvalState & state, Env & env, Value & v) { if (!state.evalBool(env, *cond, pos, "in the condition of the assert statement")) { - std::ostringstream out; - cond->show(state.ctx.symbols, out); - state.ctx.errors.make("assertion '%1%' failed", out.str()).atPos(pos).withFrame(env, *this).debugThrow(); + state.ctx.errors.make("assertion failed") + .atPos(pos) + .withFrame(env, *this) + .debugThrow(); } body->eval(state, env, v); } diff --git a/tests/functional/lang/eval-fail-assert.err.exp b/tests/functional/lang/eval-fail-assert.err.exp index 4bb63c29a..e7e573f2b 100644 --- a/tests/functional/lang/eval-fail-assert.err.exp +++ b/tests/functional/lang/eval-fail-assert.err.exp @@ -13,7 +13,7 @@ error: | ^ 3| in - error: assertion '(arg == "y")' failed + error: assertion failed at /pwd/lang/eval-fail-assert.nix:2:12: 1| let 2| x = arg: assert arg == "y"; 123; diff --git a/tests/unit/libexpr/value/print.cc b/tests/unit/libexpr/value/print.cc index a65c7f1c7..44cfb496f 100644 --- a/tests/unit/libexpr/value/print.cc +++ b/tests/unit/libexpr/value/print.cc @@ -514,7 +514,7 @@ TEST_F(ValuePrintingTests, ansiColorsAssert) ASSERT_EQ(v.type(), nAttrs); test(*v.attrs->begin()->value, - ANSI_RED "«error: assertion 'false' failed»" ANSI_NORMAL, + ANSI_RED "«error: assertion failed»" ANSI_NORMAL, PrintOptions { .ansiColors = true, .force = true