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
This commit is contained in:
@@ -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.
|
||||
+4
-3
@@ -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<AssertionError>("assertion '%1%' failed", out.str()).atPos(pos).withFrame(env, *this).debugThrow();
|
||||
state.ctx.errors.make<AssertionError>("assertion failed")
|
||||
.atPos(pos)
|
||||
.withFrame(env, *this)
|
||||
.debugThrow();
|
||||
}
|
||||
body->eval(state, env, v);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user