* New primop: abort "error message".
This commit is contained in:
parent
4a053bfdfd
commit
38f18aa6d4
4 changed files with 12 additions and 2 deletions
|
@ -515,7 +515,7 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||||
try {
|
try {
|
||||||
return concatStrings(state, args);
|
return concatStrings(state, args);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addPrefix(format("in a string concatenation: "));
|
e.addPrefix(format("in a string concatenation:\n"));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -527,7 +527,7 @@ Expr evalExpr2(EvalState & state, Expr e)
|
||||||
ATermList l2 = evalList(state, e2);
|
ATermList l2 = evalList(state, e2);
|
||||||
return makeList(ATconcat(l1, l2));
|
return makeList(ATconcat(l1, l2));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
e.addPrefix(format("in a list concatenation: "));
|
e.addPrefix(format("in a list concatenation:\n"));
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
MakeError(EvalError, Error)
|
MakeError(EvalError, Error)
|
||||||
MakeError(AssertionError, EvalError)
|
MakeError(AssertionError, EvalError)
|
||||||
|
MakeError(Abort, EvalError)
|
||||||
MakeError(TypeError, EvalError)
|
MakeError(TypeError, EvalError)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -629,6 +629,13 @@ static Expr primDependencyClosure(EvalState & state, const ATermVector & args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Expr primAbort(EvalState & state, const ATermVector & args)
|
||||||
|
{
|
||||||
|
throw Abort(format("evaluation aborted with the following error message: %1%") %
|
||||||
|
evalString(state, args[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Apply a function to every element of a list. */
|
/* Apply a function to every element of a list. */
|
||||||
static Expr primMap(EvalState & state, const ATermVector & args)
|
static Expr primMap(EvalState & state, const ATermVector & args)
|
||||||
{
|
{
|
||||||
|
@ -700,6 +707,7 @@ void EvalState::addPrimOps()
|
||||||
addPrimOp("toString", 1, primToString);
|
addPrimOp("toString", 1, primToString);
|
||||||
addPrimOp("isNull", 1, primIsNull);
|
addPrimOp("isNull", 1, primIsNull);
|
||||||
addPrimOp("dependencyClosure", 1, primDependencyClosure);
|
addPrimOp("dependencyClosure", 1, primDependencyClosure);
|
||||||
|
addPrimOp("abort", 1, primAbort);
|
||||||
|
|
||||||
addPrimOp("map", 2, primMap);
|
addPrimOp("map", 2, primMap);
|
||||||
addPrimOp("removeAttrs", 2, primRemoveAttrs);
|
addPrimOp("removeAttrs", 2, primRemoveAttrs);
|
||||||
|
|
1
tests/lang/eval-fail-abort.nix
Normal file
1
tests/lang/eval-fail-abort.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
if true then abort "this should fail" else 1
|
Loading…
Reference in a new issue