From 38f18aa6d418515e42b688fa9b3e4f3ab61bb89e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Aug 2006 15:46:00 +0000 Subject: [PATCH] * New primop: abort "error message". --- src/libexpr/eval.cc | 4 ++-- src/libexpr/nixexpr.hh | 1 + src/libexpr/primops.cc | 8 ++++++++ tests/lang/eval-fail-abort.nix | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/lang/eval-fail-abort.nix diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index ce38e2ab92..c4f5d7f5d6 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -515,7 +515,7 @@ Expr evalExpr2(EvalState & state, Expr e) try { return concatStrings(state, args); } catch (Error & e) { - e.addPrefix(format("in a string concatenation: ")); + e.addPrefix(format("in a string concatenation:\n")); throw; } } @@ -527,7 +527,7 @@ Expr evalExpr2(EvalState & state, Expr e) ATermList l2 = evalList(state, e2); return makeList(ATconcat(l1, l2)); } catch (Error & e) { - e.addPrefix(format("in a list concatenation: ")); + e.addPrefix(format("in a list concatenation:\n")); throw; } } diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 28ac35e604..3eb4d4cb2b 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -11,6 +11,7 @@ MakeError(EvalError, Error) MakeError(AssertionError, EvalError) +MakeError(Abort, EvalError) MakeError(TypeError, EvalError) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index bc4db2d813..2bc5459d13 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -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. */ static Expr primMap(EvalState & state, const ATermVector & args) { @@ -700,6 +707,7 @@ void EvalState::addPrimOps() addPrimOp("toString", 1, primToString); addPrimOp("isNull", 1, primIsNull); addPrimOp("dependencyClosure", 1, primDependencyClosure); + addPrimOp("abort", 1, primAbort); addPrimOp("map", 2, primMap); addPrimOp("removeAttrs", 2, primRemoveAttrs); diff --git a/tests/lang/eval-fail-abort.nix b/tests/lang/eval-fail-abort.nix new file mode 100644 index 0000000000..75c51bceb5 --- /dev/null +++ b/tests/lang/eval-fail-abort.nix @@ -0,0 +1 @@ +if true then abort "this should fail" else 1