From cdda2454f61921d2ea7acbb74120934411137dc5 Mon Sep 17 00:00:00 2001 From: piegames Date: Wed, 13 Nov 2024 10:22:50 +0100 Subject: [PATCH] libexpr: Assert: Don't print assertion in error message The `show` functionality needs to be removed because it is deeply flawed, and given that we already print position information in the error message (which probably wasn't always the case in the past) the assertion printing is redundant anyways. Change-Id: I1f5e05ab73aaa0ec92994c2211463260fd374898 --- doc/manual/rl-next/error-message-improvements.md | 9 +++++++++ lix/libexpr/eval.cc | 7 ++++--- tests/functional/lang/eval-fail-assert.err.exp | 2 +- tests/unit/libexpr/value/print.cc | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 doc/manual/rl-next/error-message-improvements.md 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