aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-04-16 15:03:19 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-04-16 15:03:19 +0000
commit5f2492eaecfe8d3451812e894852b1330492e827 (patch)
treeafb46441b5131d6cfddade0be9de64d95ebc2981 /src
parent0a8eeea9d8060b9d25891ccc5a9d55e32bf829ba (diff)
* New primop "throw <string>" to throw an error. This is like abort,
only thrown errors are caught by the top-level derivation evaluation in nix-env -qa / -i.
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.cc3
-rw-r--r--src/libexpr/nixexpr.hh1
-rw-r--r--src/libexpr/primops.cc9
3 files changed, 13 insertions, 0 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 456bc25f3..552b58625 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -616,6 +616,9 @@ static char * deepestStack = (char *) -1; /* for measuring stack usage */
Expr evalExpr2(EvalState & state, Expr e)
{
+ /* When changing this function, make sure that you don't cause a
+ (large) increase in stack consumption! */
+
char x;
if (&x < deepestStack) deepestStack = &x;
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 420911a87..dabbaa323 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -12,6 +12,7 @@ namespace nix {
MakeError(EvalError, Error)
MakeError(AssertionError, EvalError)
+MakeError(ThrownError, AssertionError)
MakeError(Abort, EvalError)
MakeError(TypeError, EvalError)
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index aca5f5856..c7fbca0bb 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -269,6 +269,14 @@ static Expr prim_abort(EvalState & state, const ATermVector & args)
}
+static Expr prim_throw(EvalState & state, const ATermVector & args)
+{
+ PathSet context;
+ throw ThrownError(format("user-thrown exception: `%1%'") %
+ evalString(state, args[0], context));
+}
+
+
/* Return an environment variable. Use with care. */
static Expr prim_getEnv(EvalState & state, const ATermVector & args)
{
@@ -878,6 +886,7 @@ void EvalState::addPrimOps()
addPrimOp("isNull", 1, prim_isNull);
addPrimOp("dependencyClosure", 1, prim_dependencyClosure);
addPrimOp("abort", 1, prim_abort);
+ addPrimOp("throw", 1, prim_throw);
addPrimOp("__getEnv", 1, prim_getEnv);
addPrimOp("relativise", 2, prim_relativise);