mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
Style tweaks
This commit is contained in:
parent
ba035f7dd0
commit
91b7d5373a
9 changed files with 165 additions and 370 deletions
|
@ -274,6 +274,6 @@ void printClosureDiff(
|
||||||
|
|
||||||
|
|
||||||
void runRepl(
|
void runRepl(
|
||||||
EvalState &evalState,
|
EvalState & evalState,
|
||||||
const ValMap & extraEnv);
|
const ValMap & extraEnv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ struct NixRepl
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
std::string curDir;
|
std::string curDir;
|
||||||
EvalState &state;
|
EvalState & state;
|
||||||
Bindings * autoArgs;
|
Bindings * autoArgs;
|
||||||
|
|
||||||
size_t debugTraceIndex;
|
size_t debugTraceIndex;
|
||||||
|
@ -63,11 +63,11 @@ struct NixRepl
|
||||||
|
|
||||||
const Path historyFile;
|
const Path historyFile;
|
||||||
|
|
||||||
NixRepl(EvalState &state);
|
NixRepl(EvalState & state);
|
||||||
~NixRepl();
|
~NixRepl();
|
||||||
void mainLoop(const std::vector<std::string> & files);
|
void mainLoop(const std::vector<std::string> & files);
|
||||||
StringSet completePrefix(const std::string & prefix);
|
StringSet completePrefix(const std::string & prefix);
|
||||||
bool getLine(std::string & input, const std::string &prompt);
|
bool getLine(std::string & input, const std::string & prompt);
|
||||||
StorePath getDerivationPath(Value & v);
|
StorePath getDerivationPath(Value & v);
|
||||||
bool processLine(std::string line);
|
bool processLine(std::string line);
|
||||||
void loadFile(const Path & path);
|
void loadFile(const Path & path);
|
||||||
|
@ -96,7 +96,7 @@ std::string removeWhitespace(std::string s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NixRepl::NixRepl(EvalState &state)
|
NixRepl::NixRepl(EvalState & state)
|
||||||
: state(state)
|
: state(state)
|
||||||
, debugTraceIndex(0)
|
, debugTraceIndex(0)
|
||||||
, staticEnv(new StaticEnv(false, state.staticBaseEnv.get()))
|
, staticEnv(new StaticEnv(false, state.staticBaseEnv.get()))
|
||||||
|
|
|
@ -554,20 +554,14 @@ std::string AttrCursor::getString()
|
||||||
debug("using cached string attribute '%s'", getAttrPathStr());
|
debug("using cached string attribute '%s'", getAttrPathStr());
|
||||||
return s->first;
|
return s->first;
|
||||||
} else
|
} else
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string", getAttrPathStr()));
|
||||||
auto e = TypeError("'%s' is not a string", getAttrPathStr());
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & v = forceValue();
|
auto & v = forceValue();
|
||||||
|
|
||||||
if (v.type() != nString && v.type() != nPath)
|
if (v.type() != nString && v.type() != nPath)
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
|
||||||
auto e = TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.type() == nString ? v.string.s : v.path;
|
return v.type() == nString ? v.string.s : v.path;
|
||||||
}
|
}
|
||||||
|
@ -591,10 +585,7 @@ string_t AttrCursor::getStringWithContext()
|
||||||
return *s;
|
return *s;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string", getAttrPathStr()));
|
||||||
auto e = TypeError("'%s' is not a string", getAttrPathStr());
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,10 +596,7 @@ string_t AttrCursor::getStringWithContext()
|
||||||
else if (v.type() == nPath)
|
else if (v.type() == nPath)
|
||||||
return {v.path, {}};
|
return {v.path, {}};
|
||||||
else
|
else
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
|
||||||
auto e = TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AttrCursor::getBool()
|
bool AttrCursor::getBool()
|
||||||
|
@ -621,20 +609,14 @@ bool AttrCursor::getBool()
|
||||||
debug("using cached Boolean attribute '%s'", getAttrPathStr());
|
debug("using cached Boolean attribute '%s'", getAttrPathStr());
|
||||||
return *b;
|
return *b;
|
||||||
} else
|
} else
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a Boolean", getAttrPathStr()));
|
||||||
auto e = TypeError("'%s' is not a Boolean", getAttrPathStr());
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & v = forceValue();
|
auto & v = forceValue();
|
||||||
|
|
||||||
if (v.type() != nBool)
|
if (v.type() != nBool)
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a Boolean", getAttrPathStr()));
|
||||||
auto e = TypeError("'%s' is not a Boolean", getAttrPathStr());
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return v.boolean;
|
return v.boolean;
|
||||||
}
|
}
|
||||||
|
@ -682,20 +664,14 @@ std::vector<Symbol> AttrCursor::getAttrs()
|
||||||
debug("using cached attrset attribute '%s'", getAttrPathStr());
|
debug("using cached attrset attribute '%s'", getAttrPathStr());
|
||||||
return *attrs;
|
return *attrs;
|
||||||
} else
|
} else
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not an attribute set", getAttrPathStr()));
|
||||||
auto e = TypeError("'%s' is not an attribute set", getAttrPathStr());
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & v = forceValue();
|
auto & v = forceValue();
|
||||||
|
|
||||||
if (v.type() != nAttrs)
|
if (v.type() != nAttrs)
|
||||||
{
|
root->state.debugThrowLastTrace(TypeError("'%s' is not an attribute set", getAttrPathStr()));
|
||||||
auto e = TypeError("'%s' is not an attribute set", getAttrPathStr());
|
|
||||||
root->state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Symbol> attrs;
|
std::vector<Symbol> attrs;
|
||||||
for (auto & attr : *getValue().attrs)
|
for (auto & attr : *getValue().attrs)
|
||||||
|
|
|
@ -816,7 +816,7 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr &
|
||||||
// double check we've got the debugRepl function pointer.
|
// double check we've got the debugRepl function pointer.
|
||||||
if (!debugRepl)
|
if (!debugRepl)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto dts =
|
auto dts =
|
||||||
error && expr.getPos()
|
error && expr.getPos()
|
||||||
? std::make_unique<DebugTraceStacker>(
|
? std::make_unique<DebugTraceStacker>(
|
||||||
|
@ -846,198 +846,160 @@ void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr &
|
||||||
exceptions. */
|
exceptions. */
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr & expr)
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrow(EvalError({
|
||||||
.msg = hintfmt(s),
|
.msg = hintfmt(s),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s)
|
void EvalState::throwEvalError(const PosIdx pos, const char * s)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s),
|
.msg = hintfmt(s),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const char * s, const std::string & s2)
|
void EvalState::throwEvalError(const char * s, const std::string & s2)
|
||||||
{
|
{
|
||||||
auto error = EvalError(s, s2);
|
debugThrowLastTrace(EvalError(s, s2));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
||||||
const std::string & s2, Env & env, Expr & expr)
|
const std::string & s2, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
auto error = EvalError(ErrorInfo{
|
debugThrow(EvalError(ErrorInfo{
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos],
|
.errPos = positions[pos],
|
||||||
.suggestions = suggestions,
|
.suggestions = suggestions,
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2)
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2, Env & env, Expr & expr)
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrow(EvalError({
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const char * s, const std::string & s2,
|
void EvalState::throwEvalError(const char * s, const std::string & s2,
|
||||||
const std::string & s3)
|
const std::string & s3)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[noPos]
|
.errPos = positions[noPos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||||
const std::string & s3)
|
const std::string & s3)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||||
const std::string & s3, Env & env, Expr & expr)
|
const std::string & s3, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
auto error = EvalError({
|
debugThrow(EvalError({
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2, Env & env, Expr & expr)
|
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
// p1 is where the error occurred; p2 is a position mentioned in the message.
|
// p1 is where the error occurred; p2 is a position mentioned in the message.
|
||||||
auto error = EvalError({
|
debugThrow(EvalError({
|
||||||
.msg = hintfmt(s, symbols[sym], positions[p2]),
|
.msg = hintfmt(s, symbols[sym], positions[p2]),
|
||||||
.errPos = positions[p1]
|
.errPos = positions[p1]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v)
|
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v)
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
debugThrowLastTrace(TypeError({
|
||||||
.msg = hintfmt(s, showType(v)),
|
.msg = hintfmt(s, showType(v)),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v, Env & env, Expr & expr)
|
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
debugThrow(TypeError({
|
||||||
.msg = hintfmt(s, showType(v)),
|
.msg = hintfmt(s, showType(v)),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s)
|
void EvalState::throwTypeError(const PosIdx pos, const char * s)
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
debugThrowLastTrace(TypeError({
|
||||||
.msg = hintfmt(s),
|
.msg = hintfmt(s),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
debugThrowLastTrace(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun,
|
void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun,
|
||||||
const Symbol s2, Env & env, Expr &expr)
|
const Symbol s2, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
debugThrow(TypeError({
|
||||||
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
||||||
const ExprLambda & fun, const Symbol s2, Env & env, Expr &expr)
|
const ExprLambda & fun, const Symbol s2, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
auto error = TypeError(ErrorInfo {
|
debugThrow(TypeError(ErrorInfo {
|
||||||
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
||||||
.errPos = positions[pos],
|
.errPos = positions[pos],
|
||||||
.suggestions = suggestions,
|
.suggestions = suggestions,
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr &expr)
|
void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
auto error = TypeError({
|
debugThrow(TypeError({
|
||||||
.msg = hintfmt(s, showType(v)),
|
.msg = hintfmt(s, showType(v)),
|
||||||
.errPos = positions[expr.getPos()],
|
.errPos = positions[expr.getPos()],
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
auto error = AssertionError({
|
debugThrow(AssertionError({
|
||||||
.msg = hintfmt(s, s1),
|
.msg = hintfmt(s, s1),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
auto error = UndefinedVarError({
|
debugThrow(UndefinedVarError({
|
||||||
.msg = hintfmt(s, s1),
|
.msg = hintfmt(s, s1),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
auto error = MissingArgumentError({
|
debugThrow(MissingArgumentError({
|
||||||
.msg = hintfmt(s, s1),
|
.msg = hintfmt(s, s1),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
|
|
||||||
debugThrow(error, env, expr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::addErrorTrace(Error & e, const char * s, const std::string & s2) const
|
void EvalState::addErrorTrace(Error & e, const char * s, const std::string & s2) const
|
||||||
|
|
|
@ -131,11 +131,11 @@ public:
|
||||||
bool debugStop;
|
bool debugStop;
|
||||||
bool debugQuit;
|
bool debugQuit;
|
||||||
std::list<DebugTrace> debugTraces;
|
std::list<DebugTrace> debugTraces;
|
||||||
std::map<const Expr*, const std::shared_ptr<const StaticEnv> > exprEnvs;
|
std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
|
||||||
const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr &expr) const
|
const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr & expr) const
|
||||||
{
|
{
|
||||||
auto i = exprEnvs.find(&expr);
|
auto i = exprEnvs.find(&expr);
|
||||||
if (i != exprEnvs.end())
|
if (i != exprEnvs.end())
|
||||||
return i->second;
|
return i->second;
|
||||||
else
|
else
|
||||||
return std::shared_ptr<const StaticEnv>();;
|
return std::shared_ptr<const StaticEnv>();;
|
||||||
|
@ -145,7 +145,7 @@ public:
|
||||||
|
|
||||||
template<class E>
|
template<class E>
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void debugThrow(const E &error, const Env & env, const Expr & expr)
|
void debugThrow(E && error, const Env & env, const Expr & expr)
|
||||||
{
|
{
|
||||||
if (debugRepl)
|
if (debugRepl)
|
||||||
runDebugRepl(&error, env, expr);
|
runDebugRepl(&error, env, expr);
|
||||||
|
@ -155,7 +155,7 @@ public:
|
||||||
|
|
||||||
template<class E>
|
template<class E>
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void debugThrowLastTrace(E & e)
|
void debugThrowLastTrace(E && e)
|
||||||
{
|
{
|
||||||
// Call this in the situation where Expr and Env are inaccessible.
|
// Call this in the situation where Expr and Env are inaccessible.
|
||||||
// The debugger will start in the last context that's in the
|
// The debugger will start in the last context that's in the
|
||||||
|
|
|
@ -782,14 +782,13 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string_view path, c
|
||||||
if (hasPrefix(path, "nix/"))
|
if (hasPrefix(path, "nix/"))
|
||||||
return concatStrings(corepkgsPrefix, path.substr(4));
|
return concatStrings(corepkgsPrefix, path.substr(4));
|
||||||
|
|
||||||
auto e = ThrownError({
|
debugThrowLastTrace(ThrownError({
|
||||||
.msg = hintfmt(evalSettings.pureEval
|
.msg = hintfmt(evalSettings.pureEval
|
||||||
? "cannot look up '<%s>' in pure evaluation mode (use '--impure' to override)"
|
? "cannot look up '<%s>' in pure evaluation mode (use '--impure' to override)"
|
||||||
: "file '%s' was not found in the Nix search path (add it using $NIX_PATH or -I)",
|
: "file '%s' was not found in the Nix search path (add it using $NIX_PATH or -I)",
|
||||||
path),
|
path),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
debugThrowLastTrace(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,10 +46,7 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
auto [ctx, outputName] = decodeContext(*store, i);
|
auto [ctx, outputName] = decodeContext(*store, i);
|
||||||
auto ctxS = store->printStorePath(ctx);
|
auto ctxS = store->printStorePath(ctx);
|
||||||
if (!store->isValidPath(ctx))
|
if (!store->isValidPath(ctx))
|
||||||
{
|
debugThrowLastTrace(InvalidPathError(store->printStorePath(ctx)));
|
||||||
auto e = InvalidPathError(store->printStorePath(ctx));
|
|
||||||
debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
if (!outputName.empty() && ctx.isDerivation()) {
|
if (!outputName.empty() && ctx.isDerivation()) {
|
||||||
drvs.push_back({ctx, {outputName}});
|
drvs.push_back({ctx, {outputName}});
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,12 +57,9 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
if (drvs.empty()) return {};
|
if (drvs.empty()) return {};
|
||||||
|
|
||||||
if (!evalSettings.enableImportFromDerivation)
|
if (!evalSettings.enableImportFromDerivation)
|
||||||
{
|
debugThrowLastTrace(Error(
|
||||||
auto e = 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)));
|
||||||
debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Build/substitute the context. */
|
/* Build/substitute the context. */
|
||||||
std::vector<DerivedPath> buildReqs;
|
std::vector<DerivedPath> buildReqs;
|
||||||
|
@ -77,11 +71,9 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
const auto outputPaths = store->queryDerivationOutputMap(drvPath);
|
const auto outputPaths = store->queryDerivationOutputMap(drvPath);
|
||||||
for (auto & outputName : outputs) {
|
for (auto & outputName : outputs) {
|
||||||
auto outputPath = get(outputPaths, outputName);
|
auto outputPath = get(outputPaths, outputName);
|
||||||
if (!outputPath) {
|
if (!outputPath)
|
||||||
auto e = Error("derivation '%s' does not have an output named '%s'",
|
debugThrowLastTrace(Error("derivation '%s' does not have an output named '%s'",
|
||||||
store->printStorePath(drvPath), outputName);
|
store->printStorePath(drvPath), outputName));
|
||||||
debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
res.insert_or_assign(
|
res.insert_or_assign(
|
||||||
downstreamPlaceholder(*store, drvPath, outputName),
|
downstreamPlaceholder(*store, drvPath, outputName),
|
||||||
store->printStorePath(*outputPath)
|
store->printStorePath(*outputPath)
|
||||||
|
@ -326,23 +318,17 @@ void prim_importNative(EvalState & state, const PosIdx pos, Value * * args, Valu
|
||||||
std::string sym(state.forceStringNoCtx(*args[1], pos));
|
std::string sym(state.forceStringNoCtx(*args[1], pos));
|
||||||
|
|
||||||
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
||||||
if (!handle) {
|
if (!handle)
|
||||||
auto e = EvalError("could not open '%1%': %2%", path, dlerror());
|
state.debugThrowLastTrace(EvalError("could not open '%1%': %2%", path, dlerror()));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
auto e = EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message);
|
state.debugThrowLastTrace(EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message));
|
||||||
state.debugThrowLastTrace(e);
|
else
|
||||||
} else {
|
state.debugThrowLastTrace(EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected", sym, path));
|
||||||
auto e = EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected",
|
|
||||||
sym, path);
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(func)(state, v);
|
(func)(state, v);
|
||||||
|
@ -357,13 +343,11 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
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)
|
||||||
auto e = EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("at least one argument to 'exec' required"),
|
.msg = hintfmt("at least one argument to 'exec' required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
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();
|
||||||
Strings commandArgs;
|
Strings commandArgs;
|
||||||
|
@ -373,12 +357,11 @@ void prim_exec(EvalState & state, const PosIdx 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) {
|
||||||
auto ee = EvalError({
|
state.debugThrowLastTrace(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 = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(ee);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto output = runProgram(program, true, commandArgs);
|
auto output = runProgram(program, true, commandArgs);
|
||||||
|
@ -561,10 +544,8 @@ struct CompareValues
|
||||||
return v1->fpoint < v2->integer;
|
return v1->fpoint < v2->integer;
|
||||||
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())
|
||||||
auto e = EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
|
state.debugThrowLastTrace(EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2)));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
switch (v1->type()) {
|
switch (v1->type()) {
|
||||||
case nInt:
|
case nInt:
|
||||||
return v1->integer < v2->integer;
|
return v1->integer < v2->integer;
|
||||||
|
@ -585,10 +566,8 @@ struct CompareValues
|
||||||
return (*this)(v1->listElems()[i], v2->listElems()[i]);
|
return (*this)(v1->listElems()[i], v2->listElems()[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: {
|
default:
|
||||||
auto e = EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
|
state.debugThrowLastTrace(EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2)));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -618,11 +597,10 @@ static Bindings::iterator getAttr(
|
||||||
|
|
||||||
auto aPos = attrSet->pos;
|
auto aPos = attrSet->pos;
|
||||||
if (!aPos) {
|
if (!aPos) {
|
||||||
auto e = TypeError({
|
state.debugThrowLastTrace(TypeError({
|
||||||
.msg = errorMsg,
|
.msg = errorMsg,
|
||||||
.errPos = state.positions[pos],
|
.errPos = state.positions[pos],
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
} else {
|
} else {
|
||||||
auto e = TypeError({
|
auto e = TypeError({
|
||||||
.msg = errorMsg,
|
.msg = errorMsg,
|
||||||
|
@ -685,13 +663,11 @@ static void prim_genericClosure(EvalState & state, const PosIdx pos, Value * * a
|
||||||
|
|
||||||
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())
|
||||||
auto e = EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("attribute 'key' required"),
|
.msg = hintfmt("attribute 'key' required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
state.forceValue(*key->value, pos);
|
state.forceValue(*key->value, pos);
|
||||||
|
|
||||||
if (!doneKeys.insert(key->value).second) continue;
|
if (!doneKeys.insert(key->value).second) continue;
|
||||||
|
@ -792,10 +768,7 @@ static RegisterPrimOp primop_abort({
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
||||||
{
|
state.debugThrowLastTrace(Abort("evaluation aborted with the following error message: '%1%'", s));
|
||||||
auto e = Abort("evaluation aborted with the following error message: '%1%'", s);
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -813,8 +786,7 @@ static RegisterPrimOp primop_throw({
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
||||||
auto e = ThrownError(s);
|
state.debugThrowLastTrace(ThrownError(s));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1069,49 +1041,37 @@ static void prim_derivationStrict(EvalState & state, const PosIdx 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
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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())
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("duplicate derivation output '%1%'", j),
|
.msg = hintfmt("duplicate derivation output '%1%'", j),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
/* !!! 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")
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("invalid derivation output name 'drv'" ),
|
.msg = hintfmt("invalid derivation output name 'drv'" ),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
outputs.insert(j);
|
outputs.insert(j);
|
||||||
}
|
}
|
||||||
if (outputs.empty())
|
if (outputs.empty())
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("derivation cannot have an empty set of outputs"),
|
.msg = hintfmt("derivation cannot have an empty set of outputs"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1236,32 +1196,23 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
|
||||||
|
|
||||||
/* Do we have all required attributes? */
|
/* Do we have all required attributes? */
|
||||||
if (drv.builder == "")
|
if (drv.builder == "")
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("required attribute 'builder' missing"),
|
.msg = hintfmt("required attribute 'builder' missing"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (drv.platform == "")
|
if (drv.platform == "")
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("required attribute 'system' missing"),
|
.msg = hintfmt("required attribute 'system' missing"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check whether the derivation name is valid. */
|
/* Check whether the derivation name is valid. */
|
||||||
if (isDerivation(drvName))
|
if (isDerivation(drvName))
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = 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 = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (outputHash) {
|
if (outputHash) {
|
||||||
/* Handle fixed-output derivations.
|
/* Handle fixed-output derivations.
|
||||||
|
@ -1269,13 +1220,10 @@ static void prim_derivationStrict(EvalState & state, const PosIdx 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")
|
||||||
{
|
state.debugThrowLastTrace(Error({
|
||||||
auto e = Error({
|
|
||||||
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto h = newHashAllowEmpty(*outputHash, parseHashTypeOpt(outputHashAlgo));
|
auto h = newHashAllowEmpty(*outputHash, parseHashTypeOpt(outputHashAlgo));
|
||||||
|
|
||||||
|
@ -1443,13 +1391,10 @@ static RegisterPrimOp primop_toPath({
|
||||||
static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
if (evalSettings.pureEval)
|
if (evalSettings.pureEval)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = 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 = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
PathSet context;
|
PathSet context;
|
||||||
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));
|
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));
|
||||||
|
@ -1458,13 +1403,10 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args,
|
||||||
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))
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("path '%1%' is not in the Nix store", path),
|
.msg = hintfmt("path '%1%' is not in the Nix store", path),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
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);
|
||||||
|
@ -1567,10 +1509,7 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
auto path = realisePath(state, pos, *args[0]);
|
auto path = realisePath(state, pos, *args[0]);
|
||||||
auto s = readFile(path);
|
auto s = readFile(path);
|
||||||
if (s.find((char) 0) != std::string::npos)
|
if (s.find((char) 0) != std::string::npos)
|
||||||
{
|
state.debugThrowLastTrace(Error("the contents of the file '%1%' cannot be represented as a Nix string", path));
|
||||||
auto e = Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
StorePathSet refs;
|
StorePathSet refs;
|
||||||
if (state.store->isInStore(path)) {
|
if (state.store->isInStore(path)) {
|
||||||
try {
|
try {
|
||||||
|
@ -1622,14 +1561,12 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
auto rewrites = state.realiseContext(context);
|
auto rewrites = state.realiseContext(context);
|
||||||
path = rewriteStrings(path, rewrites);
|
path = rewriteStrings(path, rewrites);
|
||||||
} catch (InvalidPathError & e) {
|
} catch (InvalidPathError & e) {
|
||||||
auto ee = EvalError({
|
state.debugThrowLastTrace(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 = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(ee);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
searchPath.emplace_back(prefix, path);
|
searchPath.emplace_back(prefix, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1650,13 +1587,10 @@ static void prim_hashFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
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)
|
||||||
{
|
state.debugThrowLastTrace(Error({
|
||||||
auto e = Error({
|
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash type '%1%'", type),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto path = realisePath(state, pos, *args[1]);
|
auto path = realisePath(state, pos, *args[1]);
|
||||||
|
|
||||||
|
@ -1893,16 +1827,13 @@ static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Val
|
||||||
|
|
||||||
for (auto path : context) {
|
for (auto path : context) {
|
||||||
if (path.at(0) != '/')
|
if (path.at(0) != '/')
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = 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 = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
refs.insert(state.store->parseStorePath(path));
|
refs.insert(state.store->parseStorePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2060,10 +1991,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 != dstPath)
|
if (expectedHash && expectedStorePath != dstPath)
|
||||||
{
|
state.debugThrowLastTrace(Error("store path mismatch in (possibly filtered) path added from '%s'", path));
|
||||||
auto e = Error("store path mismatch in (possibly filtered) path added from '%s'", path);
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
state.allowAndSetStorePathString(dstPath, v);
|
state.allowAndSetStorePathString(dstPath, v);
|
||||||
} else
|
} else
|
||||||
state.allowAndSetStorePathString(*expectedStorePath, v);
|
state.allowAndSetStorePathString(*expectedStorePath, v);
|
||||||
|
@ -2081,15 +2009,12 @@ static void prim_filterSource(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
|
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
if (args[0]->type() != nFunction)
|
if (args[0]->type() != nFunction)
|
||||||
{
|
state.debugThrowLastTrace(TypeError({
|
||||||
auto e = 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 = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -2173,22 +2098,16 @@ static void prim_path(EvalState & state, const PosIdx 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
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
|
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
|
||||||
.errPos = state.positions[attr.pos]
|
.errPos = state.positions[attr.pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("'path' required"),
|
.msg = hintfmt("'path' required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
name = baseNameOf(path);
|
name = baseNameOf(path);
|
||||||
|
|
||||||
|
@ -2560,13 +2479,10 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!args[0]->isLambda())
|
if (!args[0]->isLambda())
|
||||||
{
|
state.debugThrowLastTrace(TypeError({
|
||||||
auto e = TypeError({
|
|
||||||
.msg = hintfmt("'functionArgs' requires a function"),
|
.msg = hintfmt("'functionArgs' requires a function"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!args[0]->lambda.fun->hasFormals()) {
|
if (!args[0]->lambda.fun->hasFormals()) {
|
||||||
v.mkAttrs(&state.emptyBindings);
|
v.mkAttrs(&state.emptyBindings);
|
||||||
|
@ -2741,13 +2657,10 @@ static void elemAt(EvalState & state, const PosIdx pos, Value & list, int n, Val
|
||||||
{
|
{
|
||||||
state.forceList(list, pos);
|
state.forceList(list, pos);
|
||||||
if (n < 0 || (unsigned int) n >= list.listSize())
|
if (n < 0 || (unsigned int) n >= list.listSize())
|
||||||
{
|
state.debugThrowLastTrace(Error({
|
||||||
auto e = Error({
|
|
||||||
.msg = hintfmt("list index %1% is out of bounds", n),
|
.msg = hintfmt("list index %1% is out of bounds", n),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
state.forceValue(*list.listElems()[n], pos);
|
state.forceValue(*list.listElems()[n], pos);
|
||||||
v = *list.listElems()[n];
|
v = *list.listElems()[n];
|
||||||
}
|
}
|
||||||
|
@ -2792,13 +2705,10 @@ static void prim_tail(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
{
|
{
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
if (args[0]->listSize() == 0)
|
if (args[0]->listSize() == 0)
|
||||||
{
|
state.debugThrowLastTrace(Error({
|
||||||
auto e = Error({
|
|
||||||
.msg = hintfmt("'tail' called on an empty list"),
|
.msg = hintfmt("'tail' called on an empty list"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -3033,13 +2943,10 @@ static void prim_genList(EvalState & state, const PosIdx pos, Value * * args, Va
|
||||||
auto len = state.forceInt(*args[1], pos);
|
auto len = state.forceInt(*args[1], pos);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("cannot create list of size %1%", len),
|
.msg = hintfmt("cannot create list of size %1%", len),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
state.mkList(v, len);
|
state.mkList(v, len);
|
||||||
|
|
||||||
|
@ -3343,13 +3250,10 @@ static void prim_div(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
|
|
||||||
NixFloat f2 = state.forceFloat(*args[1], pos);
|
NixFloat f2 = state.forceFloat(*args[1], pos);
|
||||||
if (f2 == 0)
|
if (f2 == 0)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("division by zero"),
|
.msg = hintfmt("division by zero"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
||||||
|
@ -3358,13 +3262,10 @@ static void prim_div(EvalState & state, const PosIdx 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)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("overflow in integer division"),
|
.msg = hintfmt("overflow in integer division"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
v.mkInt(i1 / i2);
|
v.mkInt(i1 / i2);
|
||||||
}
|
}
|
||||||
|
@ -3492,13 +3393,10 @@ static void prim_substring(EvalState & state, const PosIdx pos, Value * * args,
|
||||||
auto s = state.coerceToString(pos, *args[2], context);
|
auto s = state.coerceToString(pos, *args[2], context);
|
||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("negative start position in 'substring'"),
|
.msg = hintfmt("negative start position in 'substring'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
|
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
|
||||||
}
|
}
|
||||||
|
@ -3546,13 +3444,10 @@ static void prim_hashString(EvalState & state, const PosIdx 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)
|
||||||
{
|
state.debugThrowLastTrace(Error({
|
||||||
auto e = Error({
|
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash type '%1%'", type),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
PathSet context; // discarded
|
PathSet context; // discarded
|
||||||
auto s = state.forceString(*args[1], context, pos);
|
auto s = state.forceString(*args[1], context, pos);
|
||||||
|
@ -3622,18 +3517,15 @@ void prim_match(EvalState & state, const PosIdx 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++
|
||||||
auto e = EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
} else
|
||||||
} else {
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("invalid regular expression '%s'", re),
|
.msg = hintfmt("invalid regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3729,18 +3621,15 @@ void prim_split(EvalState & state, const PosIdx 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++
|
||||||
auto e = EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
} else
|
||||||
} else {
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("invalid regular expression '%s'", re),
|
.msg = hintfmt("invalid regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3816,13 +3705,10 @@ static void prim_replaceStrings(EvalState & state, const PosIdx pos, Value * * a
|
||||||
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())
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> from;
|
std::vector<std::string> from;
|
||||||
from.reserve(args[0]->listSize());
|
from.reserve(args[0]->listSize());
|
||||||
|
|
|
@ -108,22 +108,16 @@ static void fetchTree(
|
||||||
|
|
||||||
if (auto aType = args[0]->attrs->get(state.sType)) {
|
if (auto aType = args[0]->attrs->get(state.sType)) {
|
||||||
if (type)
|
if (type)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("unexpected attribute 'type'"),
|
.msg = hintfmt("unexpected attribute 'type'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
type = state.forceStringNoCtx(*aType->value, aType->pos);
|
type = state.forceStringNoCtx(*aType->value, aType->pos);
|
||||||
} else if (!type)
|
} else if (!type)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
|
.msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
attrs.emplace("type", type.value());
|
attrs.emplace("type", type.value());
|
||||||
|
|
||||||
|
@ -144,22 +138,16 @@ static void fetchTree(
|
||||||
else if (attr.value->type() == nInt)
|
else if (attr.value->type() == nInt)
|
||||||
attrs.emplace(state.symbols[attr.name], uint64_t(attr.value->integer));
|
attrs.emplace(state.symbols[attr.name], uint64_t(attr.value->integer));
|
||||||
else
|
else
|
||||||
{
|
state.debugThrowLastTrace(TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
|
||||||
auto e = TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
|
state.symbols[attr.name], showType(*attr.value)));
|
||||||
state.symbols[attr.name], showType(*attr.value));
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.allowNameArgument)
|
if (!params.allowNameArgument)
|
||||||
if (auto nameIter = attrs.find("name"); nameIter != attrs.end())
|
if (auto nameIter = attrs.find("name"); nameIter != attrs.end())
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("attribute 'name' isn’t supported in call to 'fetchTree'"),
|
.msg = hintfmt("attribute 'name' isn’t supported in call to 'fetchTree'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
input = fetchers::Input::fromAttrs(std::move(attrs));
|
input = fetchers::Input::fromAttrs(std::move(attrs));
|
||||||
} else {
|
} else {
|
||||||
|
@ -179,10 +167,7 @@ static void fetchTree(
|
||||||
input = lookupInRegistries(state.store, input).first;
|
input = lookupInRegistries(state.store, input).first;
|
||||||
|
|
||||||
if (evalSettings.pureEval && !input.isLocked())
|
if (evalSettings.pureEval && !input.isLocked())
|
||||||
{
|
state.debugThrowLastTrace(EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]));
|
||||||
auto e = EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]);
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto [tree, input2] = input.fetch(state.store);
|
auto [tree, input2] = input.fetch(state.store);
|
||||||
|
|
||||||
|
@ -221,23 +206,17 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
else if (n == "name")
|
else if (n == "name")
|
||||||
name = state.forceStringNoCtx(*attr.value, attr.pos);
|
name = state.forceStringNoCtx(*attr.value, attr.pos);
|
||||||
else
|
else
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("unsupported argument '%s' to '%s'", n, who),
|
.msg = hintfmt("unsupported argument '%s' to '%s'", n, who),
|
||||||
.errPos = state.positions[attr.pos]
|
.errPos = state.positions[attr.pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url)
|
if (!url)
|
||||||
{
|
state.debugThrowLastTrace(EvalError({
|
||||||
auto e = EvalError({
|
|
||||||
.msg = hintfmt("'url' argument required"),
|
.msg = hintfmt("'url' argument required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
url = state.forceStringNoCtx(*args[0], pos);
|
url = state.forceStringNoCtx(*args[0], pos);
|
||||||
|
|
||||||
|
@ -249,10 +228,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
name = baseNameOf(*url);
|
name = baseNameOf(*url);
|
||||||
|
|
||||||
if (evalSettings.pureEval && !expectedHash)
|
if (evalSettings.pureEval && !expectedHash)
|
||||||
{
|
state.debugThrowLastTrace(EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who));
|
||||||
auto e = EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who);
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// early exit if pinned and already in the store
|
// early exit if pinned and already in the store
|
||||||
if (expectedHash && expectedHash->type == htSHA256) {
|
if (expectedHash && expectedHash->type == htSHA256) {
|
||||||
|
@ -279,11 +255,8 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
? state.store->queryPathInfo(storePath)->narHash
|
? state.store->queryPathInfo(storePath)->narHash
|
||||||
: hashFile(htSHA256, state.store->toRealPath(storePath));
|
: hashFile(htSHA256, state.store->toRealPath(storePath));
|
||||||
if (hash != *expectedHash)
|
if (hash != *expectedHash)
|
||||||
{
|
state.debugThrowLastTrace(EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
||||||
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)));
|
||||||
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true));
|
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state.allowAndSetStorePathString(storePath, v);
|
state.allowAndSetStorePathString(storePath, v);
|
||||||
|
|
|
@ -100,8 +100,7 @@ void printValueAsJSON(EvalState & state, bool strict,
|
||||||
void ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
void ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
||||||
JSONPlaceholder & out, PathSet & context) const
|
JSONPlaceholder & out, PathSet & context) const
|
||||||
{
|
{
|
||||||
auto e = TypeError("cannot convert %1% to JSON", showType());
|
state.debugThrowLastTrace(TypeError("cannot convert %1% to JSON", showType()));
|
||||||
state.debugThrowLastTrace(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue