forked from lix-project/lix
Get rid of explicit ErrorInfo constructors
This commit is contained in:
parent
fd64e4fb96
commit
1fb762d11f
|
@ -76,8 +76,7 @@ public:
|
|||
{
|
||||
auto a = get(name);
|
||||
if (!a)
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("attribute '%s' missing", name),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -9,8 +9,7 @@ namespace nix {
|
|||
|
||||
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s))
|
||||
{
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt(s),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -24,8 +23,7 @@ LocalNoInlineNoReturn(void throwTypeError(const char * s, const Value & v))
|
|||
|
||||
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v))
|
||||
{
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt(s, showType(v)),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -519,8 +519,7 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, con
|
|||
|
||||
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const string & s2, const string & s3))
|
||||
{
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt(s, s2, s3),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -529,8 +528,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const
|
|||
LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const Symbol & sym, const Pos & p2))
|
||||
{
|
||||
// p1 is where the error occurred; p2 is a position mentioned in the message.
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt(s, sym, p2),
|
||||
.nixCode = NixCode { .errPos = p1 }
|
||||
});
|
||||
|
@ -538,8 +536,7 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const
|
|||
|
||||
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s))
|
||||
{
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt(s),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -552,8 +549,7 @@ LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s1))
|
|||
|
||||
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2))
|
||||
{
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt(s, fun.showNamePos(), s2),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -561,8 +557,7 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const
|
|||
|
||||
LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s, const string & s1))
|
||||
{
|
||||
throw AssertionError(
|
||||
ErrorInfo {
|
||||
throw AssertionError({
|
||||
.hint = hintfmt(s, s1),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -570,8 +565,7 @@ LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s,
|
|||
|
||||
LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * s, const string & s1))
|
||||
{
|
||||
throw UndefinedVarError(
|
||||
ErrorInfo {
|
||||
throw UndefinedVarError({
|
||||
.hint = hintfmt(s, s1),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1919,8 +1913,7 @@ void EvalState::printStats()
|
|||
|
||||
string ExternalValueBase::coerceToString(const Pos & pos, PathSet & context, bool copyMore, bool copyToStore) const
|
||||
{
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt("cannot coerce %1% to a string", showType()),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -268,8 +268,7 @@ void ExprVar::bindVars(const StaticEnv & env)
|
|||
enclosing `with'. If there is no `with', then we can issue an
|
||||
"undefined variable" error now. */
|
||||
if (withLevel == -1)
|
||||
throw UndefinedVarError(
|
||||
ErrorInfo {
|
||||
throw UndefinedVarError({
|
||||
.hint = hintfmt("undefined variable '%1%'", name),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -236,8 +236,7 @@ struct ExprLambda : Expr
|
|||
: pos(pos), arg(arg), matchAttrs(matchAttrs), formals(formals), body(body)
|
||||
{
|
||||
if (!arg.empty() && formals && formals->argNames.find(arg) != formals->argNames.end())
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
throw ParseError({
|
||||
.hint = hintfmt("duplicate formal function argument '%1%'", arg),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -64,8 +64,7 @@ namespace nix {
|
|||
|
||||
static void dupAttr(const AttrPath & attrPath, const Pos & pos, const Pos & prevPos)
|
||||
{
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
throw ParseError({
|
||||
.hint = hintfmt("attribute '%1%' already defined at %2%",
|
||||
showAttrPath(attrPath), prevPos),
|
||||
.nixCode = NixCode { .errPos = pos },
|
||||
|
@ -75,10 +74,8 @@ static void dupAttr(const AttrPath & attrPath, const Pos & pos, const Pos & prev
|
|||
|
||||
static void dupAttr(Symbol attr, const Pos & pos, const Pos & prevPos)
|
||||
{
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("attribute '%1%' already defined at %2%",
|
||||
attr, prevPos),
|
||||
throw ParseError({
|
||||
.hint = hintfmt("attribute '%1%' already defined at %2%", attr, prevPos),
|
||||
.nixCode = NixCode { .errPos = pos },
|
||||
});
|
||||
}
|
||||
|
@ -148,8 +145,7 @@ static void addAttr(ExprAttrs * attrs, AttrPath & attrPath,
|
|||
static void addFormal(const Pos & pos, Formals * formals, const Formal & formal)
|
||||
{
|
||||
if (!formals->argNames.insert(formal.name).second)
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
throw ParseError({
|
||||
.hint = hintfmt("duplicate formal function argument '%1%'",
|
||||
formal.name),
|
||||
.nixCode = NixCode { .errPos = pos },
|
||||
|
@ -261,7 +257,7 @@ static inline Pos makeCurPos(const YYLTYPE & loc, ParseData * data)
|
|||
|
||||
void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * error)
|
||||
{
|
||||
data->error = ErrorInfo {
|
||||
data->error = {
|
||||
.hint = hintfmt(error),
|
||||
.nixCode = NixCode { .errPos = makeCurPos(*loc, data) }
|
||||
};
|
||||
|
@ -341,8 +337,7 @@ expr_function
|
|||
{ $$ = new ExprWith(CUR_POS, $2, $4); }
|
||||
| LET binds IN expr_function
|
||||
{ if (!$2->dynamicAttrs.empty())
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
throw ParseError({
|
||||
.hint = hintfmt("dynamic attributes not allowed in let"),
|
||||
.nixCode = NixCode { .errPos = CUR_POS },
|
||||
});
|
||||
|
@ -422,8 +417,7 @@ expr_simple
|
|||
| URI {
|
||||
static bool noURLLiterals = settings.isExperimentalFeatureEnabled("no-url-literals");
|
||||
if (noURLLiterals)
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
throw ParseError({
|
||||
.hint = hintfmt("URL literals are disabled"),
|
||||
.nixCode = NixCode { .errPos = CUR_POS }
|
||||
});
|
||||
|
@ -496,8 +490,7 @@ attrs
|
|||
$$->push_back(AttrName(str->s));
|
||||
delete str;
|
||||
} else
|
||||
throw ParseError(
|
||||
ErrorInfo {
|
||||
throw ParseError({
|
||||
.hint = hintfmt("dynamic attributes not allowed in inherit"),
|
||||
.nixCode = NixCode { .errPos = makeCurPos(@2, data) },
|
||||
});
|
||||
|
@ -695,8 +688,7 @@ Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos
|
|||
Path res = r.second + suffix;
|
||||
if (pathExists(res)) return canonPath(res);
|
||||
}
|
||||
throw ThrownError(
|
||||
ErrorInfo {
|
||||
throw ThrownError({
|
||||
.hint = hintfmt("file '%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)", path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -715,8 +707,7 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
|
|||
res = { true, store->toRealPath(fetchers::downloadTarball(
|
||||
store, resolveUri(elem.second), "source", false).storePath) };
|
||||
} catch (FileTransferError & e) {
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "Entry download",
|
||||
.hint = hintfmt("Nix search path entry '%1%' cannot be downloaded, ignoring", elem.second)
|
||||
});
|
||||
|
@ -727,8 +718,7 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
|
|||
if (pathExists(path))
|
||||
res = { true, path };
|
||||
else {
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "Entry not found",
|
||||
.hint = hintfmt("warning: Nix search path entry '%1%' does not exist, ignoring", elem.second)
|
||||
});
|
||||
|
|
|
@ -93,10 +93,8 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
|
|||
try {
|
||||
state.realiseContext(context);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("cannot import '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot import '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
}
|
||||
|
@ -174,8 +172,7 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
try {
|
||||
state.realiseContext(context);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt(
|
||||
"cannot import '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
|
@ -215,8 +212,7 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
auto elems = args[0]->listElems();
|
||||
auto count = args[0]->listSize();
|
||||
if (count == 0) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("at least one argument to 'exec' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -230,12 +226,12 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
try {
|
||||
state.realiseContext(context);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
|
||||
program, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});}
|
||||
});
|
||||
}
|
||||
|
||||
auto output = runProgram(program, true, commandArgs);
|
||||
Expr * parsed;
|
||||
|
@ -386,8 +382,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
|||
Bindings::iterator startSet =
|
||||
args[0]->attrs->find(state.symbols.create("startSet"));
|
||||
if (startSet == args[0]->attrs->end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'startSet' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -401,8 +396,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
|||
Bindings::iterator op =
|
||||
args[0]->attrs->find(state.symbols.create("operator"));
|
||||
if (op == args[0]->attrs->end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'operator' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -424,8 +418,7 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
|
|||
Bindings::iterator key =
|
||||
e->attrs->find(state.symbols.create("key"));
|
||||
if (key == e->attrs->end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'key' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -560,8 +553,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
/* Figure out the name first (for stack backtraces). */
|
||||
Bindings::iterator attr = args[0]->attrs->find(state.sName);
|
||||
if (attr == args[0]->attrs->end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("required attribute 'name' missing"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -608,8 +600,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive;
|
||||
else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat;
|
||||
else
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
@ -619,8 +610,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
outputs.clear();
|
||||
for (auto & j : ss) {
|
||||
if (outputs.find(j) != outputs.end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("duplicate derivation output '%1%'", j),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
@ -630,16 +620,14 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
then we'd have an attribute ‘drvPath’ in
|
||||
the resulting set. */
|
||||
if (j == "drv")
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid derivation output name 'drv'" ),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
outputs.insert(j);
|
||||
}
|
||||
if (outputs.empty())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("derivation cannot have an empty set of outputs"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
@ -754,23 +742,20 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
|
||||
/* Do we have all required attributes? */
|
||||
if (drv.builder == "")
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("required attribute 'builder' missing"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
||||
if (drv.platform == "")
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("required attribute 'system' missing"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
||||
/* Check whether the derivation name is valid. */
|
||||
if (isDerivation(drvName))
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
@ -778,8 +763,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
|
|||
if (outputHash) {
|
||||
/* Handle fixed-output derivations. */
|
||||
if (outputs.size() != 1 || *(outputs.begin()) != "out")
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
||||
.nixCode = NixCode { .errPos = posDrvName }
|
||||
});
|
||||
|
@ -887,8 +871,7 @@ static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, V
|
|||
e.g. nix-push does the right thing. */
|
||||
if (!state.store->isStorePath(path)) path = canonPath(path, true);
|
||||
if (!state.store->isInStore(path))
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("path '%1%' is not in the Nix store", path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -907,8 +890,7 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
|
|||
try {
|
||||
state.realiseContext(context);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt(
|
||||
"cannot check the existence of '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
|
@ -956,10 +938,8 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
try {
|
||||
state.realiseContext(context);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid"
|
||||
, path, e.path),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
}
|
||||
|
@ -989,8 +969,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
|
||||
i = v2.attrs->find(state.symbols.create("path"));
|
||||
if (i == v2.attrs->end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute 'path' missing"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1001,10 +980,8 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
try {
|
||||
state.realiseContext(context);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("cannot find '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
}
|
||||
|
@ -1023,8 +1000,7 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
string type = state.forceStringNoCtx(*args[0], pos);
|
||||
HashType ht = parseHashType(type);
|
||||
if (ht == htUnknown)
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("unknown hash type '%1%'", type),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1043,10 +1019,8 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val
|
|||
try {
|
||||
state.realiseContext(ctx);
|
||||
} catch (InvalidPathError & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid",
|
||||
path, e.path),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
}
|
||||
|
@ -1118,13 +1092,11 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu
|
|||
|
||||
for (auto path : context) {
|
||||
if (path.at(0) != '/')
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError( {
|
||||
.hint = hintfmt(
|
||||
"in 'toFile': the file named '%1%' must not contain a reference "
|
||||
"to a derivation but contains (%2%)",
|
||||
name,
|
||||
path),
|
||||
name, path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
refs.insert(state.store->parseStorePath(path));
|
||||
|
@ -1194,16 +1166,14 @@ static void prim_filterSource(EvalState & state, const Pos & pos, Value * * args
|
|||
PathSet context;
|
||||
Path path = state.coerceToPath(pos, *args[1], context);
|
||||
if (!context.empty())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("string '%1%' cannot refer to other paths", path),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
||||
state.forceValue(*args[0], pos);
|
||||
if (args[0]->type != tLambda)
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt(
|
||||
"first argument in call to 'filterSource' is not a function but %1%",
|
||||
showType(*args[0])),
|
||||
|
@ -1228,10 +1198,8 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
PathSet context;
|
||||
path = state.coerceToPath(*attr.pos, *attr.value, context);
|
||||
if (!context.empty())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("string '%1%' cannot refer to other paths",
|
||||
path),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("string '%1%' cannot refer to other paths", path),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
});
|
||||
} else if (attr.name == state.sName)
|
||||
|
@ -1244,16 +1212,13 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
else if (n == "sha256")
|
||||
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
|
||||
else
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("unsupported argument '%1%' to 'addPath'",
|
||||
attr.name),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("unsupported argument '%1%' to 'addPath'", attr.name),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
});
|
||||
}
|
||||
if (path.empty())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'path' required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1314,8 +1279,7 @@ void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
// !!! Should we create a symbol here or just do a lookup?
|
||||
Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr));
|
||||
if (i == args[1]->attrs->end())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("attribute '%1%' missing", attr),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1398,8 +1362,7 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
|
|||
|
||||
Bindings::iterator j = v2.attrs->find(state.sName);
|
||||
if (j == v2.attrs->end())
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt("'name' attribute missing in a call to 'listToAttrs'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1409,8 +1372,7 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
|
|||
if (seen.insert(sym).second) {
|
||||
Bindings::iterator j2 = v2.attrs->find(state.symbols.create(state.sValue));
|
||||
if (j2 == v2.attrs->end())
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt("'value' attribute missing in a call to 'listToAttrs'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1486,8 +1448,7 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
|
|||
{
|
||||
state.forceValue(*args[0], pos);
|
||||
if (args[0]->type != tLambda)
|
||||
throw TypeError(
|
||||
ErrorInfo {
|
||||
throw TypeError({
|
||||
.hint = hintfmt("'functionArgs' requires a function"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1543,8 +1504,7 @@ static void elemAt(EvalState & state, const Pos & pos, Value & list, int n, Valu
|
|||
{
|
||||
state.forceList(list, pos);
|
||||
if (n < 0 || (unsigned int) n >= list.listSize())
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("list index %1% is out of bounds", n),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1574,8 +1534,7 @@ static void prim_tail(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
{
|
||||
state.forceList(*args[0], pos);
|
||||
if (args[0]->listSize() == 0)
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("'tail' called on an empty list"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1720,13 +1679,11 @@ static void prim_genList(EvalState & state, const Pos & pos, Value * * args, Val
|
|||
auto len = state.forceInt(*args[1], pos);
|
||||
|
||||
if (len < 0)
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("cannot create list of size %1%", len),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
||||
|
||||
state.mkList(v, len);
|
||||
|
||||
for (unsigned int n = 0; n < (unsigned int) len; ++n) {
|
||||
|
@ -1884,8 +1841,7 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
|
|||
|
||||
NixFloat f2 = state.forceFloat(*args[1], pos);
|
||||
if (f2 == 0)
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("division by zero"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1897,8 +1853,7 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
|
|||
NixInt i2 = state.forceInt(*args[1], pos);
|
||||
/* Avoid division overflow as it might raise SIGFPE. */
|
||||
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("overflow in integer division"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1959,8 +1914,7 @@ static void prim_substring(EvalState & state, const Pos & pos, Value * * args, V
|
|||
string s = state.coerceToString(pos, *args[2], context);
|
||||
|
||||
if (start < 0)
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("negative start position in 'substring'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -1983,8 +1937,7 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
|
|||
string type = state.forceStringNoCtx(*args[0], pos);
|
||||
HashType ht = parseHashType(type);
|
||||
if (ht == htUnknown)
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("unknown hash type '%1%'", type),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -2030,14 +1983,12 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
|||
} catch (std::regex_error &e) {
|
||||
if (e.code() == std::regex_constants::error_space) {
|
||||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
} else {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -2105,14 +2056,12 @@ static void prim_split(EvalState & state, const Pos & pos, Value * * args, Value
|
|||
} catch (std::regex_error &e) {
|
||||
if (e.code() == std::regex_constants::error_space) {
|
||||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
} else {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("invalid regular expression '%s'", re),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -2146,8 +2095,7 @@ static void prim_replaceStrings(EvalState & state, const Pos & pos, Value * * ar
|
|||
state.forceList(*args[0], pos);
|
||||
state.forceList(*args[1], pos);
|
||||
if (args[0]->listSize() != args[1]->listSize())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -146,8 +146,7 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
|
|||
auto sAllOutputs = state.symbols.create("allOutputs");
|
||||
for (auto & i : *args[1]->attrs) {
|
||||
if (!state.store->isStorePath(i.name))
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("Context key '%s' is not a store path", i.name),
|
||||
.nixCode = NixCode { .errPos = *i.pos }
|
||||
});
|
||||
|
@ -164,8 +163,7 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
|
|||
if (iter != i.value->attrs->end()) {
|
||||
if (state.forceBool(*iter->value, *iter->pos)) {
|
||||
if (!isDerivation(i.name)) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("Tried to add all-outputs context of %s, which is not a derivation, to a string", i.name),
|
||||
.nixCode = NixCode { .errPos = *i.pos }
|
||||
});
|
||||
|
@ -178,8 +176,7 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
|
|||
if (iter != i.value->attrs->end()) {
|
||||
state.forceList(*iter->value, *iter->pos);
|
||||
if (iter->value->listSize() && !isDerivation(i.name)) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("Tried to add derivation output context of %s, which is not a derivation, to a string", i.name),
|
||||
.nixCode = NixCode { .errPos = *i.pos }
|
||||
});
|
||||
|
|
|
@ -35,16 +35,14 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
else if (n == "submodules")
|
||||
fetchSubmodules = state.forceBool(*attr.value, *attr.pos);
|
||||
else
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("unsupported argument '%s' to 'fetchGit'", attr.name),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
});
|
||||
}
|
||||
|
||||
if (url.empty())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'url' argument required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -38,16 +38,14 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
|
|||
else if (n == "name")
|
||||
name = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||
else
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("unsupported argument '%s' to 'fetchMercurial'", attr.name),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
});
|
||||
}
|
||||
|
||||
if (url.empty())
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'url' argument required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -66,8 +66,7 @@ static void prim_fetchTree(EvalState & state, const Pos & pos, Value * * args, V
|
|||
}
|
||||
|
||||
if (!attrs.count("type"))
|
||||
throw Error(
|
||||
ErrorInfo {
|
||||
throw Error({
|
||||
.hint = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
@ -111,17 +110,14 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
|||
else if (n == "name")
|
||||
name = state.forceStringNoCtx(*attr.value, *attr.pos);
|
||||
else
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
.hint = hintfmt("unsupported argument '%s' to '%s'",
|
||||
attr.name, who),
|
||||
throw EvalError({
|
||||
.hint = hintfmt("unsupported argument '%s' to '%s'", attr.name, who),
|
||||
.nixCode = NixCode { .errPos = *attr.pos }
|
||||
});
|
||||
}
|
||||
|
||||
if (!url)
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("'url' argument required"),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -81,8 +81,7 @@ static void prim_fromTOML(EvalState & state, const Pos & pos, Value * * args, Va
|
|||
try {
|
||||
visit(v, parser(tomlStream).parse());
|
||||
} catch (std::runtime_error & e) {
|
||||
throw EvalError(
|
||||
ErrorInfo {
|
||||
throw EvalError({
|
||||
.hint = hintfmt("while parsing a TOML string: %s", e.what()),
|
||||
.nixCode = NixCode { .errPos = pos }
|
||||
});
|
||||
|
|
|
@ -22,8 +22,7 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
|
|||
srcFiles = readDirectory(srcDir);
|
||||
} catch (SysError & e) {
|
||||
if (e.errNo == ENOTDIR) {
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "Create links - directory",
|
||||
.hint = hintfmt("not including '%s' in the user environment because it's not a directory", srcDir)
|
||||
});
|
||||
|
@ -45,8 +44,7 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
|
|||
throw SysError("getting status of '%1%'", srcFile);
|
||||
} catch (SysError & e) {
|
||||
if (e.errNo == ENOENT || e.errNo == ENOTDIR) {
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "Create links - skipping symlink",
|
||||
.hint = hintfmt("skipping dangling symlink '%s'", dstFile)
|
||||
});
|
||||
|
|
|
@ -129,8 +129,7 @@ Path LocalFSStore::addPermRoot(const StorePath & storePath,
|
|||
if (settings.checkRootReachability) {
|
||||
auto roots = findRoots(false);
|
||||
if (roots[storePath.clone()].count(gcRoot) == 0)
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "GC root",
|
||||
.hint = hintfmt("warning: '%1%' is not in a directory where the garbage collector looks for roots; "
|
||||
"therefore, '%2%' might be removed by the garbage collector",
|
||||
|
|
|
@ -204,8 +204,8 @@ void handleSQLiteBusy(const SQLiteBusy & e)
|
|||
|
||||
if (now > lastWarned + 10) {
|
||||
lastWarned = now;
|
||||
logWarning(
|
||||
ErrorInfo { .name = "Sqlite busy",
|
||||
logWarning({
|
||||
.name = "Sqlite busy",
|
||||
.hint = hintfmt(e.what())
|
||||
});
|
||||
}
|
||||
|
|
|
@ -119,9 +119,9 @@ public:
|
|||
{ }
|
||||
|
||||
template<typename... Args>
|
||||
BaseError(const Args & ... args)
|
||||
BaseError(const std::string & fs, const Args & ... args)
|
||||
: err { .level = lvlError,
|
||||
.hint = hintfmt(args...)
|
||||
.hint = hintfmt(fs, args...)
|
||||
}
|
||||
{ }
|
||||
|
||||
|
@ -131,7 +131,11 @@ public:
|
|||
}
|
||||
{ }
|
||||
|
||||
BaseError(ErrorInfo e)
|
||||
BaseError(ErrorInfo && e)
|
||||
: err(std::move(e))
|
||||
{ }
|
||||
|
||||
BaseError(const ErrorInfo & e)
|
||||
: err(e)
|
||||
{ }
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ size_t threshold = 256 * 1024 * 1024;
|
|||
|
||||
static void warnLargeDump()
|
||||
{
|
||||
logWarning(ErrorInfo {
|
||||
logWarning({
|
||||
.name = "Large path",
|
||||
.description = "dumping very large path (> 256 MiB); this may run out of memory"
|
||||
});
|
||||
|
|
|
@ -368,8 +368,7 @@ static void _main(int argc, char * * argv)
|
|||
shell = drv->queryOutPath() + "/bin/bash";
|
||||
|
||||
} catch (Error & e) {
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "bashInteractive",
|
||||
.hint = hintfmt("%s; will use bash from your environment",
|
||||
(e.info().hint ? e.info().hint->str() : ""))
|
||||
|
|
|
@ -68,8 +68,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
|
||||
if (dryRun) {
|
||||
stopProgressBar();
|
||||
logWarning(
|
||||
ErrorInfo {
|
||||
logWarning({
|
||||
.name = "Version update",
|
||||
.hint = hintfmt("would upgrade to version %s", version)
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue