forked from lix-project/lix
for primops, enter the debugger at the last DebugTrace in the stack
This commit is contained in:
parent
3ff5ac3586
commit
4cffb130e3
|
@ -437,7 +437,7 @@ EvalState::EvalState(
|
||||||
, emptyBindings(0)
|
, emptyBindings(0)
|
||||||
, store(store)
|
, store(store)
|
||||||
, buildStore(buildStore ? buildStore : store)
|
, buildStore(buildStore ? buildStore : store)
|
||||||
, debugStop(true)
|
, debugStop(false)
|
||||||
, regexCache(makeRegexCache())
|
, regexCache(makeRegexCache())
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
|
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
|
||||||
|
@ -787,6 +787,17 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, Eva
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EvalState::debug_throw(Error e) {
|
||||||
|
// 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()) {
|
||||||
|
DebugTrace &last = debugTraces.front();
|
||||||
|
debuggerHook(&e, last.env, last.expr);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, Env & env, Expr *expr))
|
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, Env & env, Expr *expr))
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
auto error = EvalError({
|
||||||
|
|
|
@ -118,6 +118,8 @@ public:
|
||||||
bool debugStop;
|
bool debugStop;
|
||||||
std::list<DebugTrace> debugTraces;
|
std::list<DebugTrace> debugTraces;
|
||||||
|
|
||||||
|
void debug_throw(Error e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SrcToStore srcToStore;
|
SrcToStore srcToStore;
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
|
||||||
if (withLevel == -1)
|
if (withLevel == -1)
|
||||||
{
|
{
|
||||||
throw UndefinedVarError({
|
throw UndefinedVarError({
|
||||||
.msg = hintfmt("undefined variable (ExprVar bindvars) '%1%'", name),
|
.msg = hintfmt("undefined variable '%1%'", name),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
auto [ctxS, outputName] = decodeContext(i);
|
auto [ctxS, outputName] = decodeContext(i);
|
||||||
auto ctx = store->parseStorePath(ctxS);
|
auto ctx = store->parseStorePath(ctxS);
|
||||||
if (!store->isValidPath(ctx))
|
if (!store->isValidPath(ctx))
|
||||||
throw InvalidPathError(store->printStorePath(ctx));
|
debug_throw(InvalidPathError(store->printStorePath(ctx)));
|
||||||
if (!outputName.empty() && ctx.isDerivation()) {
|
if (!outputName.empty() && ctx.isDerivation()) {
|
||||||
drvs.push_back({ctx, {outputName}});
|
drvs.push_back({ctx, {outputName}});
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,9 +57,9 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
if (drvs.empty()) return {};
|
if (drvs.empty()) return {};
|
||||||
|
|
||||||
if (!evalSettings.enableImportFromDerivation)
|
if (!evalSettings.enableImportFromDerivation)
|
||||||
throw Error(
|
debug_throw(Error(
|
||||||
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
||||||
store->printStorePath(drvs.begin()->drvPath));
|
store->printStorePath(drvs.begin()->drvPath)));
|
||||||
|
|
||||||
/* Build/substitute the context. */
|
/* Build/substitute the context. */
|
||||||
std::vector<DerivedPath> buildReqs;
|
std::vector<DerivedPath> buildReqs;
|
||||||
|
@ -71,8 +71,8 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
auto outputPaths = store->queryDerivationOutputMap(drvPath);
|
auto outputPaths = store->queryDerivationOutputMap(drvPath);
|
||||||
for (auto & outputName : outputs) {
|
for (auto & outputName : outputs) {
|
||||||
if (outputPaths.count(outputName) == 0)
|
if (outputPaths.count(outputName) == 0)
|
||||||
throw Error("derivation '%s' does not have an output named '%s'",
|
debug_throw(Error("derivation '%s' does not have an output named '%s'",
|
||||||
store->printStorePath(drvPath), outputName);
|
store->printStorePath(drvPath), outputName));
|
||||||
res.insert_or_assign(
|
res.insert_or_assign(
|
||||||
downstreamPlaceholder(*store, drvPath, outputName),
|
downstreamPlaceholder(*store, drvPath, outputName),
|
||||||
store->printStorePath(outputPaths.at(outputName))
|
store->printStorePath(outputPaths.at(outputName))
|
||||||
|
@ -318,17 +318,17 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
|
||||||
|
|
||||||
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
||||||
if (!handle)
|
if (!handle)
|
||||||
throw EvalError("could not open '%1%': %2%", path, dlerror());
|
state.debug_throw(EvalError("could not open '%1%': %2%", path, dlerror()));
|
||||||
|
|
||||||
dlerror();
|
dlerror();
|
||||||
ValueInitializer func = (ValueInitializer) dlsym(handle, sym.c_str());
|
ValueInitializer func = (ValueInitializer) dlsym(handle, sym.c_str());
|
||||||
if(!func) {
|
if(!func) {
|
||||||
char *message = dlerror();
|
char *message = dlerror();
|
||||||
if (message)
|
if (message)
|
||||||
throw EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message);
|
state.debug_throw(EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message));
|
||||||
else
|
else
|
||||||
throw EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected",
|
state.debug_throw(EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected",
|
||||||
sym, path);
|
sym, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
(func)(state, v);
|
(func)(state, v);
|
||||||
|
@ -344,10 +344,10 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
auto elems = args[0]->listElems();
|
auto elems = args[0]->listElems();
|
||||||
auto count = args[0]->listSize();
|
auto count = args[0]->listSize();
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("at least one argument to 'exec' required"),
|
.msg = hintfmt("at least one argument to 'exec' required"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
PathSet context;
|
PathSet context;
|
||||||
auto program = state.coerceToString(pos, *elems[0], context, false, false).toOwned();
|
auto program = state.coerceToString(pos, *elems[0], context, false, false).toOwned();
|
||||||
|
@ -358,11 +358,11 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
try {
|
try {
|
||||||
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
|
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
|
||||||
} catch (InvalidPathError & e) {
|
} catch (InvalidPathError & e) {
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
|
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
|
||||||
program, e.path),
|
program, e.path),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto output = runProgram(program, true, commandArgs);
|
auto output = runProgram(program, true, commandArgs);
|
||||||
|
@ -545,7 +545,7 @@ struct CompareValues
|
||||||
if (v1->type() == nInt && v2->type() == nFloat)
|
if (v1->type() == nInt && v2->type() == nFloat)
|
||||||
return v1->integer < v2->fpoint;
|
return v1->integer < v2->fpoint;
|
||||||
if (v1->type() != v2->type())
|
if (v1->type() != v2->type())
|
||||||
throw EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
|
state.debug_throw(EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2)));
|
||||||
switch (v1->type()) {
|
switch (v1->type()) {
|
||||||
case nInt:
|
case nInt:
|
||||||
return v1->integer < v2->integer;
|
return v1->integer < v2->integer;
|
||||||
|
@ -567,7 +567,8 @@ struct CompareValues
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
|
state.debug_throw(EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2)));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -597,10 +598,10 @@ static Bindings::iterator getAttr(
|
||||||
|
|
||||||
Pos aPos = *attrSet->pos;
|
Pos aPos = *attrSet->pos;
|
||||||
if (aPos == noPos) {
|
if (aPos == noPos) {
|
||||||
throw TypeError({
|
state.debug_throw(TypeError({
|
||||||
.msg = errorMsg,
|
.msg = errorMsg,
|
||||||
.errPos = pos,
|
.errPos = pos,
|
||||||
});
|
}));
|
||||||
} else {
|
} else {
|
||||||
auto e = TypeError({
|
auto e = TypeError({
|
||||||
.msg = errorMsg,
|
.msg = errorMsg,
|
||||||
|
@ -610,7 +611,7 @@ static Bindings::iterator getAttr(
|
||||||
// Adding another trace for the function name to make it clear
|
// Adding another trace for the function name to make it clear
|
||||||
// which call received wrong arguments.
|
// which call received wrong arguments.
|
||||||
e.addTrace(pos, hintfmt("while invoking '%s'", funcName));
|
e.addTrace(pos, hintfmt("while invoking '%s'", funcName));
|
||||||
throw e;
|
state.debug_throw(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,10 +665,10 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
||||||
Bindings::iterator key =
|
Bindings::iterator key =
|
||||||
e->attrs->find(state.sKey);
|
e->attrs->find(state.sKey);
|
||||||
if (key == e->attrs->end())
|
if (key == e->attrs->end())
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("attribute 'key' required"),
|
.msg = hintfmt("attribute 'key' required"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
state.forceValue(*key->value, pos);
|
state.forceValue(*key->value, pos);
|
||||||
|
|
||||||
if (!doneKeys.insert(key->value).second) continue;
|
if (!doneKeys.insert(key->value).second) continue;
|
||||||
|
@ -734,7 +735,7 @@ static RegisterPrimOp primop_abort({
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
string s = state.coerceToString(pos, *args[0], context).toOwned();
|
string s = state.coerceToString(pos, *args[0], context).toOwned();
|
||||||
throw Abort("evaluation aborted with the following error message: '%1%'", s);
|
state.debug_throw(Abort("evaluation aborted with the following error message: '%1%'", s));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -752,7 +753,7 @@ static RegisterPrimOp primop_throw({
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
string s = state.coerceToString(pos, *args[0], context).toOwned();
|
string s = state.coerceToString(pos, *args[0], context).toOwned();
|
||||||
throw ThrownError(s);
|
state.debug_throw(ThrownError(s));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1006,37 +1007,37 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
||||||
if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive;
|
if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive;
|
||||||
else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat;
|
else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat;
|
||||||
else
|
else
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto handleOutputs = [&](const Strings & ss) {
|
auto handleOutputs = [&](const Strings & ss) {
|
||||||
outputs.clear();
|
outputs.clear();
|
||||||
for (auto & j : ss) {
|
for (auto & j : ss) {
|
||||||
if (outputs.find(j) != outputs.end())
|
if (outputs.find(j) != outputs.end())
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("duplicate derivation output '%1%'", j),
|
.msg = hintfmt("duplicate derivation output '%1%'", j),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
/* !!! Check whether j is a valid attribute
|
/* !!! Check whether j is a valid attribute
|
||||||
name. */
|
name. */
|
||||||
/* Derivations cannot be named ‘drv’, because
|
/* Derivations cannot be named ‘drv’, because
|
||||||
then we'd have an attribute ‘drvPath’ in
|
then we'd have an attribute ‘drvPath’ in
|
||||||
the resulting set. */
|
the resulting set. */
|
||||||
if (j == "drv")
|
if (j == "drv")
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("invalid derivation output name 'drv'" ),
|
.msg = hintfmt("invalid derivation output name 'drv'" ),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
outputs.insert(j);
|
outputs.insert(j);
|
||||||
}
|
}
|
||||||
if (outputs.empty())
|
if (outputs.empty())
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("derivation cannot have an empty set of outputs"),
|
.msg = hintfmt("derivation cannot have an empty set of outputs"),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1155,23 +1156,23 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
||||||
|
|
||||||
/* Do we have all required attributes? */
|
/* Do we have all required attributes? */
|
||||||
if (drv.builder == "")
|
if (drv.builder == "")
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("required attribute 'builder' missing"),
|
.msg = hintfmt("required attribute 'builder' missing"),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (drv.platform == "")
|
if (drv.platform == "")
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("required attribute 'system' missing"),
|
.msg = hintfmt("required attribute 'system' missing"),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
|
|
||||||
/* Check whether the derivation name is valid. */
|
/* Check whether the derivation name is valid. */
|
||||||
if (isDerivation(drvName))
|
if (isDerivation(drvName))
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
|
.msg = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (outputHash) {
|
if (outputHash) {
|
||||||
/* Handle fixed-output derivations.
|
/* Handle fixed-output derivations.
|
||||||
|
@ -1179,10 +1180,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
||||||
Ignore `__contentAddressed` because fixed output derivations are
|
Ignore `__contentAddressed` because fixed output derivations are
|
||||||
already content addressed. */
|
already content addressed. */
|
||||||
if (outputs.size() != 1 || *(outputs.begin()) != "out")
|
if (outputs.size() != 1 || *(outputs.begin()) != "out")
|
||||||
throw Error({
|
state.debug_throw(Error({
|
||||||
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
||||||
.errPos = posDrvName
|
.errPos = posDrvName
|
||||||
});
|
}));
|
||||||
|
|
||||||
std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo);
|
std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo);
|
||||||
Hash h = newHashAllowEmpty(*outputHash, ht);
|
Hash h = newHashAllowEmpty(*outputHash, ht);
|
||||||
|
@ -1350,10 +1351,10 @@ static RegisterPrimOp primop_toPath({
|
||||||
static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
if (evalSettings.pureEval)
|
if (evalSettings.pureEval)
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("'%s' is not allowed in pure evaluation mode", "builtins.storePath"),
|
.msg = hintfmt("'%s' is not allowed in pure evaluation mode", "builtins.storePath"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
PathSet context;
|
PathSet context;
|
||||||
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));
|
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));
|
||||||
|
@ -1362,10 +1363,10 @@ static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, V
|
||||||
e.g. nix-push does the right thing. */
|
e.g. nix-push does the right thing. */
|
||||||
if (!state.store->isStorePath(path)) path = canonPath(path, true);
|
if (!state.store->isStorePath(path)) path = canonPath(path, true);
|
||||||
if (!state.store->isInStore(path))
|
if (!state.store->isInStore(path))
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("path '%1%' is not in the Nix store", path),
|
.msg = hintfmt("path '%1%' is not in the Nix store", path),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
auto path2 = state.store->toStorePath(path).first;
|
auto path2 = state.store->toStorePath(path).first;
|
||||||
if (!settings.readOnlyMode)
|
if (!settings.readOnlyMode)
|
||||||
state.store->ensurePath(path2);
|
state.store->ensurePath(path2);
|
||||||
|
@ -1468,7 +1469,7 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
|
||||||
auto path = realisePath(state, pos, *args[0]);
|
auto path = realisePath(state, pos, *args[0]);
|
||||||
string s = readFile(path);
|
string s = readFile(path);
|
||||||
if (s.find((char) 0) != string::npos)
|
if (s.find((char) 0) != string::npos)
|
||||||
throw Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
|
state.debug_throw(Error("the contents of the file '%1%' cannot be represented as a Nix string", path));
|
||||||
StorePathSet refs;
|
StorePathSet refs;
|
||||||
if (state.store->isInStore(path)) {
|
if (state.store->isInStore(path)) {
|
||||||
try {
|
try {
|
||||||
|
@ -1520,10 +1521,10 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
|
||||||
auto rewrites = state.realiseContext(context);
|
auto rewrites = state.realiseContext(context);
|
||||||
path = rewriteStrings(path, rewrites);
|
path = rewriteStrings(path, rewrites);
|
||||||
} catch (InvalidPathError & e) {
|
} catch (InvalidPathError & e) {
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
|
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1547,10 +1548,10 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
|
||||||
auto type = state.forceStringNoCtx(*args[0], pos);
|
auto type = state.forceStringNoCtx(*args[0], pos);
|
||||||
std::optional<HashType> ht = parseHashType(type);
|
std::optional<HashType> ht = parseHashType(type);
|
||||||
if (!ht)
|
if (!ht)
|
||||||
throw Error({
|
state.debug_throw(Error({
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash type '%1%'", type),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
auto path = realisePath(state, pos, *args[1]);
|
auto path = realisePath(state, pos, *args[1]);
|
||||||
|
|
||||||
|
@ -1787,13 +1788,13 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu
|
||||||
|
|
||||||
for (auto path : context) {
|
for (auto path : context) {
|
||||||
if (path.at(0) != '/')
|
if (path.at(0) != '/')
|
||||||
throw EvalError( {
|
state.debug_throw(EvalError( {
|
||||||
.msg = hintfmt(
|
.msg = hintfmt(
|
||||||
"in 'toFile': the file named '%1%' must not contain a reference "
|
"in 'toFile': the file named '%1%' must not contain a reference "
|
||||||
"to a derivation but contains (%2%)",
|
"to a derivation but contains (%2%)",
|
||||||
name, path),
|
name, path),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
refs.insert(state.store->parseStorePath(path));
|
refs.insert(state.store->parseStorePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1951,7 +1952,7 @@ static void addPath(
|
||||||
? state.store->computeStorePathForPath(name, path, method, htSHA256, filter).first
|
? state.store->computeStorePathForPath(name, path, method, htSHA256, filter).first
|
||||||
: state.store->addToStore(name, path, method, htSHA256, filter, state.repair, refs));
|
: state.store->addToStore(name, path, method, htSHA256, filter, state.repair, refs));
|
||||||
if (expectedHash && expectedStorePath != state.store->parseStorePath(dstPath))
|
if (expectedHash && expectedStorePath != state.store->parseStorePath(dstPath))
|
||||||
throw Error("store path mismatch in (possibly filtered) path added from '%s'", path);
|
state.debug_throw(Error("store path mismatch in (possibly filtered) path added from '%s'", path));
|
||||||
} else
|
} else
|
||||||
dstPath = state.store->printStorePath(*expectedStorePath);
|
dstPath = state.store->printStorePath(*expectedStorePath);
|
||||||
|
|
||||||
|
@ -1973,12 +1974,12 @@ static void prim_filterSource(EvalState & state, const Pos & pos, Value * * args
|
||||||
|
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
if (args[0]->type() != nFunction)
|
if (args[0]->type() != nFunction)
|
||||||
throw TypeError({
|
state.debug_throw(TypeError({
|
||||||
.msg = hintfmt(
|
.msg = hintfmt(
|
||||||
"first argument in call to 'filterSource' is not a function but %1%",
|
"first argument in call to 'filterSource' is not a function but %1%",
|
||||||
showType(*args[0])),
|
showType(*args[0])),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, std::nullopt, v, context);
|
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, std::nullopt, v, context);
|
||||||
}
|
}
|
||||||
|
@ -2062,16 +2063,16 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
|
||||||
else if (n == "sha256")
|
else if (n == "sha256")
|
||||||
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
|
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
|
||||||
else
|
else
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", attr.name),
|
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", attr.name),
|
||||||
.errPos = *attr.pos
|
.errPos = *attr.pos
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("'path' required"),
|
.msg = hintfmt("'path' required"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
name = baseNameOf(path);
|
name = baseNameOf(path);
|
||||||
|
|
||||||
|
@ -2442,10 +2443,10 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!args[0]->isLambda())
|
if (!args[0]->isLambda())
|
||||||
throw TypeError({
|
state.debug_throw(TypeError({
|
||||||
.msg = hintfmt("'functionArgs' requires a function"),
|
.msg = hintfmt("'functionArgs' requires a function"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (!args[0]->lambda.fun->hasFormals()) {
|
if (!args[0]->lambda.fun->hasFormals()) {
|
||||||
v.mkAttrs(&state.emptyBindings);
|
v.mkAttrs(&state.emptyBindings);
|
||||||
|
@ -2620,10 +2621,10 @@ static void elemAt(EvalState & state, const Pos & pos, Value & list, int n, Valu
|
||||||
{
|
{
|
||||||
state.forceList(list, pos);
|
state.forceList(list, pos);
|
||||||
if (n < 0 || (unsigned int) n >= list.listSize())
|
if (n < 0 || (unsigned int) n >= list.listSize())
|
||||||
throw Error({
|
state.debug_throw(Error({
|
||||||
.msg = hintfmt("list index %1% is out of bounds", n),
|
.msg = hintfmt("list index %1% is out of boundz", n),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
state.forceValue(*list.listElems()[n], pos);
|
state.forceValue(*list.listElems()[n], pos);
|
||||||
v = *list.listElems()[n];
|
v = *list.listElems()[n];
|
||||||
}
|
}
|
||||||
|
@ -2668,10 +2669,10 @@ static void prim_tail(EvalState & state, const Pos & pos, Value * * args, Value
|
||||||
{
|
{
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
if (args[0]->listSize() == 0)
|
if (args[0]->listSize() == 0)
|
||||||
throw Error({
|
state.debug_throw(Error({
|
||||||
.msg = hintfmt("'tail' called on an empty list"),
|
.msg = hintfmt("'tail' called on an empty list"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
state.mkList(v, args[0]->listSize() - 1);
|
state.mkList(v, args[0]->listSize() - 1);
|
||||||
for (unsigned int n = 0; n < v.listSize(); ++n)
|
for (unsigned int n = 0; n < v.listSize(); ++n)
|
||||||
|
@ -2906,10 +2907,10 @@ static void prim_genList(EvalState & state, const Pos & pos, Value * * args, Val
|
||||||
auto len = state.forceInt(*args[1], pos);
|
auto len = state.forceInt(*args[1], pos);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("cannot create list of size %1%", len),
|
.msg = hintfmt("cannot create list of size %1%", len),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
state.mkList(v, len);
|
state.mkList(v, len);
|
||||||
|
|
||||||
|
@ -3213,10 +3214,10 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
|
||||||
|
|
||||||
NixFloat f2 = state.forceFloat(*args[1], pos);
|
NixFloat f2 = state.forceFloat(*args[1], pos);
|
||||||
if (f2 == 0)
|
if (f2 == 0)
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("division by zero"),
|
.msg = hintfmt("division by zero"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (args[0]->type() == nFloat || args[1]->type() == nFloat) {
|
if (args[0]->type() == nFloat || args[1]->type() == nFloat) {
|
||||||
v.mkFloat(state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos));
|
v.mkFloat(state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos));
|
||||||
|
@ -3225,10 +3226,10 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
|
||||||
NixInt i2 = state.forceInt(*args[1], pos);
|
NixInt i2 = state.forceInt(*args[1], pos);
|
||||||
/* Avoid division overflow as it might raise SIGFPE. */
|
/* Avoid division overflow as it might raise SIGFPE. */
|
||||||
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
|
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("overflow in integer division"),
|
.msg = hintfmt("overflow in integer division"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
v.mkInt(i1 / i2);
|
v.mkInt(i1 / i2);
|
||||||
}
|
}
|
||||||
|
@ -3356,10 +3357,10 @@ static void prim_substring(EvalState & state, const Pos & pos, Value * * args, V
|
||||||
auto s = state.coerceToString(pos, *args[2], context);
|
auto s = state.coerceToString(pos, *args[2], context);
|
||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("negative start position in 'substring'"),
|
.msg = hintfmt("negative start position in 'substring'"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
|
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
|
||||||
}
|
}
|
||||||
|
@ -3407,10 +3408,10 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
|
||||||
auto type = state.forceStringNoCtx(*args[0], pos);
|
auto type = state.forceStringNoCtx(*args[0], pos);
|
||||||
std::optional<HashType> ht = parseHashType(type);
|
std::optional<HashType> ht = parseHashType(type);
|
||||||
if (!ht)
|
if (!ht)
|
||||||
throw Error({
|
state.debug_throw(Error({
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash type '%1%'", type),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
PathSet context; // discarded
|
PathSet context; // discarded
|
||||||
auto s = state.forceString(*args[1], context, pos);
|
auto s = state.forceString(*args[1], context, pos);
|
||||||
|
@ -3480,15 +3481,15 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
} catch (std::regex_error &e) {
|
} catch (std::regex_error &e) {
|
||||||
if (e.code() == std::regex_constants::error_space) {
|
if (e.code() == std::regex_constants::error_space) {
|
||||||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
} else {
|
} else {
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("invalid regular expression '%s'", re),
|
.msg = hintfmt("invalid regular expression '%s'", re),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3585,15 +3586,15 @@ void prim_split(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
} catch (std::regex_error &e) {
|
} catch (std::regex_error &e) {
|
||||||
if (e.code() == std::regex_constants::error_space) {
|
if (e.code() == std::regex_constants::error_space) {
|
||||||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
} else {
|
} else {
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("invalid regular expression '%s'", re),
|
.msg = hintfmt("invalid regular expression '%s'", re),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3670,10 +3671,10 @@ static void prim_replaceStrings(EvalState & state, const Pos & pos, Value * * ar
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
state.forceList(*args[1], pos);
|
state.forceList(*args[1], pos);
|
||||||
if (args[0]->listSize() != args[1]->listSize())
|
if (args[0]->listSize() != args[1]->listSize())
|
||||||
throw EvalError({
|
state.debug_throw(EvalError({
|
||||||
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
||||||
.errPos = pos
|
.errPos = pos
|
||||||
});
|
}));
|
||||||
|
|
||||||
vector<string> from;
|
vector<string> from;
|
||||||
from.reserve(args[0]->listSize());
|
from.reserve(args[0]->listSize());
|
||||||
|
|
Loading…
Reference in a new issue