aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libexpr/eval-cache.cc25
-rw-r--r--src/libexpr/eval.cc94
-rw-r--r--src/libexpr/eval.hh26
-rw-r--r--src/libexpr/parser.y3
-rw-r--r--src/libexpr/primops.cc153
-rw-r--r--src/libexpr/primops/fetchTree.cc27
-rw-r--r--src/libexpr/value-to-json.cc5
7 files changed, 121 insertions, 212 deletions
diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc
index e9d9d02a4..af213a484 100644
--- a/src/libexpr/eval-cache.cc
+++ b/src/libexpr/eval-cache.cc
@@ -556,8 +556,7 @@ std::string AttrCursor::getString()
} else
{
auto e = TypeError("'%s' is not a string", getAttrPathStr());
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
}
}
@@ -567,8 +566,7 @@ std::string AttrCursor::getString()
if (v.type() != nString && v.type() != nPath)
{
auto e = TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
return v.type() == nString ? v.string.s : v.path;
@@ -595,8 +593,7 @@ string_t AttrCursor::getStringWithContext()
} else
{
auto e = TypeError("'%s' is not a string", getAttrPathStr());
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
}
}
@@ -610,9 +607,7 @@ string_t AttrCursor::getStringWithContext()
else
{
auto e = TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
- root->state.debugLastTrace(e);
- throw e;
- return {v.path, {}}; // should never execute
+ root->state.debugThrowLastTrace(e);
}
}
@@ -628,8 +623,7 @@ bool AttrCursor::getBool()
} else
{
auto e = TypeError("'%s' is not a Boolean", getAttrPathStr());
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
}
}
@@ -639,8 +633,7 @@ bool AttrCursor::getBool()
if (v.type() != nBool)
{
auto e = TypeError("'%s' is not a Boolean", getAttrPathStr());
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
return v.boolean;
@@ -691,8 +684,7 @@ std::vector<Symbol> AttrCursor::getAttrs()
} else
{
auto e = TypeError("'%s' is not an attribute set", getAttrPathStr());
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
}
}
@@ -702,8 +694,7 @@ std::vector<Symbol> AttrCursor::getAttrs()
if (v.type() != nAttrs)
{
auto e = TypeError("'%s' is not an attribute set", getAttrPathStr());
- root->state.debugLastTrace(e);
- throw e;
+ root->state.debugThrowLastTrace(e);
}
std::vector<Symbol> attrs;
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 003fbdf11..c36bb59fb 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -810,24 +810,6 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
return vm;
}
-void EvalState::debugLastTrace(Error & e) const
-{
- // Call this in the situation where Expr and Env are inaccessible.
- // The debugger will start in the last context that's in the
- // DebugTrace stack.
- if (debuggerHook && !debugTraces.empty()) {
- const DebugTrace & last = debugTraces.front();
- debuggerHook(&e, last.env, last.expr);
- }
-}
-
-void debugError(Error * e, Env & env, Expr & expr)
-{
- if (debuggerHook)
- debuggerHook(e, env, expr);
-}
-
-
/* Every "format" object (even temporary) takes up a few hundred bytes
of stack space, which is a real killer in the recursive
evaluator. So here are some helper functions for throwing
@@ -839,9 +821,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwEvalError(const PosIdx pos, const char * s) const
@@ -851,18 +831,14 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s) const
.errPos = positions[pos]
});
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwEvalError(const char * s, const std::string & s2) const
{
auto error = EvalError(s, s2);
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
@@ -874,9 +850,7 @@ void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions
.suggestions = suggestions,
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2) const
@@ -886,9 +860,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
.errPos = positions[pos]
});
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2, Env & env, Expr & expr) const
@@ -898,9 +870,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwEvalError(const char * s, const std::string & s2,
@@ -911,9 +881,7 @@ void EvalState::throwEvalError(const char * s, const std::string & s2,
.errPos = positions[noPos]
});
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
@@ -924,9 +892,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
.errPos = positions[pos]
});
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
@@ -937,9 +903,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2, Env & env, Expr & expr) const
@@ -950,9 +914,7 @@ void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym
.errPos = positions[p1]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v) const
@@ -962,9 +924,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v
.errPos = positions[pos]
});
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v, Env & env, Expr & expr) const
@@ -974,9 +934,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwTypeError(const PosIdx pos, const char * s) const
@@ -986,9 +944,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s) const
.errPos = positions[pos]
});
- debugLastTrace(error);
-
- throw error;
+ debugThrowLastTrace(error);
}
void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun,
@@ -999,9 +955,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambd
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
@@ -1013,9 +967,7 @@ void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions
.suggestions = suggestions,
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr &expr) const
@@ -1025,9 +977,7 @@ void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr
.errPos = positions[expr.getPos()],
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr) const
@@ -1037,9 +987,7 @@ void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std:
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr) const
@@ -1049,9 +997,7 @@ void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const s
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr) const
@@ -1061,9 +1007,7 @@ void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, cons
.errPos = positions[pos]
});
- debugError(&error, env, expr);
-
- throw error;
+ debugThrow(error, env, expr);
}
void EvalState::addErrorTrace(Error & e, const char * s, const std::string & s2) const
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 96ee224f8..f274278be 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -130,7 +130,31 @@ public:
bool debugStop;
bool debugQuit;
std::list<DebugTrace> debugTraces;
- void debugLastTrace(Error & e) const;
+
+ template<class E>
+ [[gnu::noinline, gnu::noreturn]]
+ void debugThrow(const E &error, const Env & env, const Expr & expr) const
+ {
+ if (debuggerHook)
+ debuggerHook(&error, env, expr);
+
+ throw error;
+ }
+
+ template<class E>
+ [[gnu::noinline, gnu::noreturn]]
+ void debugThrowLastTrace(E & e) const
+ {
+ // Call this in the situation where Expr and Env are inaccessible.
+ // The debugger will start in the last context that's in the
+ // DebugTrace stack.
+ if (debuggerHook && !debugTraces.empty()) {
+ const DebugTrace & last = debugTraces.front();
+ debuggerHook(&e, last.env, last.expr);
+ }
+
+ throw e;
+ }
private:
SrcToStore srcToStore;
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 8edafdd57..b960cd8df 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -789,8 +789,7 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string_view path, c
path),
.errPos = positions[pos]
});
- debugLastTrace(e);
- throw e;
+ debugThrowLastTrace(e);
}
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index de8d74292..d2b94b95c 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -48,8 +48,7 @@ StringMap EvalState::realiseContext(const PathSet & context)
if (!store->isValidPath(ctx))
{
auto e = InvalidPathError(store->printStorePath(ctx));
- debugLastTrace(e);
- throw e;
+ debugThrowLastTrace(e);
}
if (!outputName.empty() && ctx.isDerivation()) {
drvs.push_back({ctx, {outputName}});
@@ -65,8 +64,7 @@ StringMap EvalState::realiseContext(const PathSet & context)
auto e = Error(
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
store->printStorePath(drvs.begin()->drvPath));
- debugLastTrace(e);
- throw e;
+ debugThrowLastTrace(e);
}
/* Build/substitute the context. */
@@ -82,8 +80,7 @@ StringMap EvalState::realiseContext(const PathSet & context)
if (!outputPath) {
auto e = Error("derivation '%s' does not have an output named '%s'",
store->printStorePath(drvPath), outputName);
- debugLastTrace(e);
- throw e;
+ debugThrowLastTrace(e);
}
res.insert_or_assign(
downstreamPlaceholder(*store, drvPath, outputName),
@@ -331,8 +328,7 @@ void prim_importNative(EvalState & state, const PosIdx pos, Value * * args, Valu
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!handle) {
auto e = EvalError("could not open '%1%': %2%", path, dlerror());
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
dlerror();
@@ -341,13 +337,11 @@ void prim_importNative(EvalState & state, const PosIdx pos, Value * * args, Valu
char *message = dlerror();
if (message) {
auto e = EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
} else {
auto e = EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected",
sym, path);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
@@ -368,8 +362,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
.msg = hintfmt("at least one argument to 'exec' required"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
PathSet context;
auto program = state.coerceToString(pos, *elems[0], context, false, false).toOwned();
@@ -385,8 +378,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
program, e.path),
.errPos = state.positions[pos]
});
- state.debugLastTrace(ee);
- throw ee;
+ state.debugThrowLastTrace(ee);
}
auto output = runProgram(program, true, commandArgs);
@@ -571,8 +563,7 @@ struct CompareValues
return v1->integer < v2->fpoint;
if (v1->type() != v2->type()) {
auto e = EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
switch (v1->type()) {
case nInt:
@@ -596,8 +587,7 @@ struct CompareValues
}
default: {
auto e = EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
}
@@ -632,8 +622,7 @@ static Bindings::iterator getAttr(
.msg = errorMsg,
.errPos = state.positions[pos],
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
} else {
auto e = TypeError({
.msg = errorMsg,
@@ -643,8 +632,7 @@ static Bindings::iterator getAttr(
// Adding another trace for the function name to make it clear
// which call received wrong arguments.
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", funcName));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
@@ -702,8 +690,7 @@ static void prim_genericClosure(EvalState & state, const PosIdx pos, Value * * a
.msg = hintfmt("attribute 'key' required"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
state.forceValue(*key->value, pos);
@@ -807,8 +794,7 @@ static RegisterPrimOp primop_abort({
auto s = state.coerceToString(pos, *args[0], context).toOwned();
{
auto e = Abort("evaluation aborted with the following error message: '%1%'", s);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
});
@@ -828,8 +814,7 @@ static RegisterPrimOp primop_throw({
PathSet context;
auto s = state.coerceToString(pos, *args[0], context).toOwned();
auto e = ThrownError(s);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
});
@@ -893,6 +878,7 @@ static RegisterPrimOp primop_floor({
* else => {success=false; value=false;} */
static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v)
{
+ std::cout << "priatraynasdf0" << std::endl;
auto attrs = state.buildBindings(2);
auto saveDebuggerHook = debuggerHook;
debuggerHook = nullptr;
@@ -900,7 +886,15 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
state.forceValue(*args[0], pos);
attrs.insert(state.sValue, args[0]);
attrs.alloc("success").mkBool(true);
+ std::cout << "priatraynasdf0000" << std::endl;
} catch (AssertionError & e) {
+ std::cout << "priatraynasdf" << std::endl;
+
+ attrs.alloc(state.sValue).mkBool(false);
+ attrs.alloc("success").mkBool(false);
+ } catch (Error & e) {
+ std::cout << "priatraERASERynasdf" << std::endl;
+
attrs.alloc(state.sValue).mkBool(false);
attrs.alloc("success").mkBool(false);
}
@@ -1092,8 +1086,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
};
@@ -1106,8 +1099,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("duplicate derivation output '%1%'", j),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
/* !!! Check whether j is a valid attribute
name. */
@@ -1120,8 +1112,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("invalid derivation output name 'drv'" ),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
outputs.insert(j);
}
@@ -1131,8 +1122,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("derivation cannot have an empty set of outputs"),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
};
@@ -1263,8 +1253,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("required attribute 'builder' missing"),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
if (drv.platform == "")
@@ -1273,8 +1262,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("required attribute 'system' missing"),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
/* Check whether the derivation name is valid. */
@@ -1284,8 +1272,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
if (outputHash) {
@@ -1299,8 +1286,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
.errPos = state.positions[posDrvName]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
auto h = newHashAllowEmpty(*outputHash, parseHashTypeOpt(outputHashAlgo));
@@ -1474,8 +1460,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args,
.msg = hintfmt("'%s' is not allowed in pure evaluation mode", "builtins.storePath"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
PathSet context;
@@ -1490,8 +1475,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args,
.msg = hintfmt("path '%1%' is not in the Nix store", path),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
auto path2 = state.store->toStorePath(path).first;
if (!settings.readOnlyMode)
@@ -1597,8 +1581,7 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, V
if (s.find((char) 0) != std::string::npos)
{
auto e = Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
StorePathSet refs;
if (state.store->isInStore(path)) {
@@ -1655,8 +1638,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
.errPos = state.positions[pos]
});
- state.debugLastTrace(ee);
- throw ee;
+ state.debugThrowLastTrace(ee);
}
@@ -1685,8 +1667,7 @@ static void prim_hashFile(EvalState & state, const PosIdx pos, Value * * args, V
.msg = hintfmt("unknown hash type '%1%'", type),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
auto path = realisePath(state, pos, *args[1]);
@@ -1932,8 +1913,7 @@ static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Val
name, path),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
refs.insert(state.store->parseStorePath(path));
}
@@ -2094,8 +2074,7 @@ static void addPath(
if (expectedHash && expectedStorePath != dstPath)
{
auto e = Error("store path mismatch in (possibly filtered) path added from '%s'", path);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
state.allowAndSetStorePathString(dstPath, v);
} else
@@ -2121,8 +2100,7 @@ static void prim_filterSource(EvalState & state, const PosIdx pos, Value * * arg
showType(*args[0])),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, std::nullopt, v, context);
@@ -2212,8 +2190,7 @@ static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
.errPos = state.positions[attr.pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
if (path.empty())
@@ -2222,8 +2199,7 @@ static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value
.msg = hintfmt("'path' required"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
if (name.empty())
name = baseNameOf(path);
@@ -2601,8 +2577,7 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value * * arg
.msg = hintfmt("'functionArgs' requires a function"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
if (!args[0]->lambda.fun->hasFormals()) {
@@ -2691,8 +2666,7 @@ static void prim_zipAttrsWith(EvalState & state, const PosIdx pos, Value * * arg
attrsSeen[attr.name].first++;
} catch (TypeError & e) {
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", "zipAttrsWith"));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
@@ -2784,8 +2758,7 @@ static void elemAt(EvalState & state, const PosIdx pos, Value & list, int n, Val
.msg = hintfmt("list index %1% is out of bounds", n),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
state.forceValue(*list.listElems()[n], pos);
v = *list.listElems()[n];
@@ -2836,8 +2809,7 @@ static void prim_tail(EvalState & state, const PosIdx pos, Value * * args, Value
.msg = hintfmt("'tail' called on an empty list"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
state.mkList(v, args[0]->listSize() - 1);
@@ -3078,8 +3050,7 @@ static void prim_genList(EvalState & state, const PosIdx pos, Value * * args, Va
.msg = hintfmt("cannot create list of size %1%", len),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
state.mkList(v, len);
@@ -3289,8 +3260,7 @@ static void prim_concatMap(EvalState & state, const PosIdx pos, Value * * args,
state.forceList(lists[n], lists[n].determinePos(args[0]->determinePos(pos)));
} catch (TypeError &e) {
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", "concatMap"));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
len += lists[n].listSize();
}
@@ -3390,8 +3360,7 @@ static void prim_div(EvalState & state, const PosIdx pos, Value * * args, Value
.msg = hintfmt("division by zero"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
if (args[0]->type() == nFloat || args[1]->type() == nFloat) {
@@ -3406,8 +3375,7 @@ static void prim_div(EvalState & state, const PosIdx pos, Value * * args, Value
.msg = hintfmt("overflow in integer division"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
v.mkInt(i1 / i2);
@@ -3541,8 +3509,7 @@ static void prim_substring(EvalState & state, const PosIdx pos, Value * * args,
.msg = hintfmt("negative start position in 'substring'"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
@@ -3596,8 +3563,7 @@ static void prim_hashString(EvalState & state, const PosIdx pos, Value * * args,
.msg = hintfmt("unknown hash type '%1%'", type),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
PathSet context; // discarded
@@ -3672,15 +3638,13 @@ void prim_match(EvalState & state, const PosIdx pos, Value * * args, Value & v)
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
} else {
auto e = EvalError({
.msg = hintfmt("invalid regular expression '%s'", re),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
}
@@ -3781,15 +3745,13 @@ void prim_split(EvalState & state, const PosIdx pos, Value * * args, Value & v)
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
} else {
auto e = EvalError({
.msg = hintfmt("invalid regular expression '%s'", re),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
}
@@ -3871,8 +3833,7 @@ static void prim_replaceStrings(EvalState & state, const PosIdx pos, Value * * a
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
std::vector<std::string> from;
diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc
index 55fe7da24..e4fa3c5f9 100644
--- a/src/libexpr/primops/fetchTree.cc
+++ b/src/libexpr/primops/fetchTree.cc
@@ -113,8 +113,7 @@ static void fetchTree(
.msg = hintfmt("unexpected attribute 'type'"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
type = state.forceStringNoCtx(*aType->value, aType->pos);
} else if (!type)
@@ -123,8 +122,7 @@ static void fetchTree(
.msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
attrs.emplace("type", type.value());
@@ -149,8 +147,7 @@ static void fetchTree(
{
auto e = TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
state.symbols[attr.name], showType(*attr.value));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
@@ -161,8 +158,7 @@ static void fetchTree(
.msg = hintfmt("attribute 'name' isn’t supported in call to 'fetchTree'"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
input = fetchers::Input::fromAttrs(std::move(attrs));
@@ -185,8 +181,7 @@ static void fetchTree(
if (evalSettings.pureEval && !input.isLocked())
{
auto e = EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
auto [tree, input2] = input.fetch(state.store);
@@ -231,8 +226,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
.msg = hintfmt("unsupported argument '%s' to '%s'", n, who),
.errPos = state.positions[attr.pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
@@ -242,8 +236,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
.msg = hintfmt("'url' argument required"),
.errPos = state.positions[pos]
});
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
} else
url = state.forceStringNoCtx(*args[0], pos);
@@ -258,8 +251,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
if (evalSettings.pureEval && !expectedHash)
{
auto e = EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who);
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
// early exit if pinned and already in the store
@@ -290,8 +282,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
{
auto e = EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true));
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}
}
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index 34f3a34c8..6a95e0414 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -85,7 +85,7 @@ void printValueAsJSON(EvalState & state, bool strict,
.errPos = state.positions[v.determinePos(pos)]
});
e.addTrace(state.positions[pos], hintfmt("message for the trace"));
- state.debugLastTrace(e);
+ state.debugThrowLastTrace(e);
throw e;
}
}
@@ -101,8 +101,7 @@ void ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
JSONPlaceholder & out, PathSet & context) const
{
auto e = TypeError("cannot convert %1% to JSON", showType());
- state.debugLastTrace(e);
- throw e;
+ state.debugThrowLastTrace(e);
}