diff options
author | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-01-27T14·36+0000 |
---|---|---|
committer | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-01-27T14·36+0000 |
commit | 110606d470c22928a505296b694751c7d17a5c03 (patch) | |
tree | dafea43ee23ff1ab16a5b04173a9ac6076627109 /src/libexpr/primops.cc | |
parent | 061141e63256842bd72160a30302b31463222411 (diff) |
Add the "addErrorContext" builtin to add more information in the stack trace.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 14 |
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); |