about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libexpr/primops.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index dce56c9a217c..1413615e3bcc 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -190,6 +190,19 @@ static Expr prim_throw(EvalState & state, const ATermVector & args)
 }
 
 
+static Expr prim_addErrorContext(EvalState & state, const ATermVector & args)
+{
+    PathSet context;
+    try {
+        return evalExpr(state, args[1]);
+    } catch (Error & e) {
+        e.addPrefix(format("%1%\n") %
+            evalString(state, args[0], context));
+        throw;
+    }
+}
+
+
 /* Return an environment variable.  Use with care. */
 static Expr prim_getEnv(EvalState & state, const ATermVector & args)
 {
@@ -976,6 +989,7 @@ void EvalState::addPrimOps()
     addPrimOp("__genericClosure", 1, prim_genericClosure);
     addPrimOp("abort", 1, prim_abort);
     addPrimOp("throw", 1, prim_throw);
+    addPrimOp("__addErrorContext", 2, prim_addErrorContext);
     addPrimOp("__getEnv", 1, prim_getEnv);
     addPrimOp("__trace", 2, prim_trace);