Get rid of explicit ErrorInfo constructors

This commit is contained in:
Eelco Dolstra 2020-06-15 14:06:58 +02:00
parent fd64e4fb96
commit 1fb762d11f
19 changed files with 360 additions and 447 deletions

View file

@ -76,11 +76,10 @@ public:
{ {
auto a = get(name); auto a = get(name);
if (!a) if (!a)
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("attribute '%s' missing", name),
.hint = hintfmt("attribute '%s' missing", name), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
return *a; return *a;
} }

View file

@ -9,11 +9,10 @@ namespace nix {
LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s)) LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s))
{ {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt(s),
.hint = hintfmt(s), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
LocalNoInlineNoReturn(void throwTypeError(const char * s, const Value & v)) LocalNoInlineNoReturn(void throwTypeError(const char * s, const Value & v))
@ -24,11 +23,10 @@ LocalNoInlineNoReturn(void throwTypeError(const char * s, const Value & v))
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v)) LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v))
{ {
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt(s, showType(v)),
.hint = hintfmt(s, showType(v)), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }

View file

@ -519,30 +519,27 @@ 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)) LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s, const string & s2, const string & s3))
{ {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt(s, s2, s3),
.hint = hintfmt(s, s2, s3), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
LocalNoInlineNoReturn(void throwEvalError(const Pos & p1, const char * s, const Symbol & sym, const Pos & p2)) 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. // p1 is where the error occurred; p2 is a position mentioned in the message.
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt(s, sym, p2),
.hint = hintfmt(s, sym, p2), .nixCode = NixCode { .errPos = p1 }
.nixCode = NixCode { .errPos = p1 } });
});
} }
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s)) LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s))
{ {
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt(s),
.hint = hintfmt(s), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s1)) LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s1))
@ -552,29 +549,26 @@ LocalNoInlineNoReturn(void throwTypeError(const char * s, const string & s1))
LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2)) LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const ExprLambda & fun, const Symbol & s2))
{ {
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt(s, fun.showNamePos(), s2),
.hint = hintfmt(s, fun.showNamePos(), s2), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s, const string & s1)) LocalNoInlineNoReturn(void throwAssertionError(const Pos & pos, const char * s, const string & s1))
{ {
throw AssertionError( throw AssertionError({
ErrorInfo { .hint = hintfmt(s, s1),
.hint = hintfmt(s, s1), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * s, const string & s1)) LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char * s, const string & s1))
{ {
throw UndefinedVarError( throw UndefinedVarError({
ErrorInfo { .hint = hintfmt(s, s1),
.hint = hintfmt(s, s1), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2)) LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2))
@ -1919,11 +1913,10 @@ void EvalState::printStats()
string ExternalValueBase::coerceToString(const Pos & pos, PathSet & context, bool copyMore, bool copyToStore) const string ExternalValueBase::coerceToString(const Pos & pos, PathSet & context, bool copyMore, bool copyToStore) const
{ {
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt("cannot coerce %1% to a string", showType()),
.hint = hintfmt("cannot coerce %1% to a string", showType()), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }

View file

@ -268,11 +268,10 @@ void ExprVar::bindVars(const StaticEnv & env)
enclosing `with'. If there is no `with', then we can issue an enclosing `with'. If there is no `with', then we can issue an
"undefined variable" error now. */ "undefined variable" error now. */
if (withLevel == -1) if (withLevel == -1)
throw UndefinedVarError( throw UndefinedVarError({
ErrorInfo { .hint = hintfmt("undefined variable '%1%'", name),
.hint = hintfmt("undefined variable '%1%'", name), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
fromWith = true; fromWith = true;
this->level = withLevel; this->level = withLevel;
} }

View file

@ -236,11 +236,10 @@ struct ExprLambda : Expr
: pos(pos), arg(arg), matchAttrs(matchAttrs), formals(formals), body(body) : pos(pos), arg(arg), matchAttrs(matchAttrs), formals(formals), body(body)
{ {
if (!arg.empty() && formals && formals->argNames.find(arg) != formals->argNames.end()) if (!arg.empty() && formals && formals->argNames.find(arg) != formals->argNames.end())
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("duplicate formal function argument '%1%'", arg),
.hint = hintfmt("duplicate formal function argument '%1%'", arg), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
}; };
void setName(Symbol & name); void setName(Symbol & name);
string showNamePos() const; string showNamePos() const;

View file

@ -64,23 +64,20 @@ namespace nix {
static void dupAttr(const AttrPath & attrPath, const Pos & pos, const Pos & prevPos) static void dupAttr(const AttrPath & attrPath, const Pos & pos, const Pos & prevPos)
{ {
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("attribute '%1%' already defined at %2%",
.hint = hintfmt("attribute '%1%' already defined at %2%", showAttrPath(attrPath), prevPos),
showAttrPath(attrPath), prevPos), .nixCode = NixCode { .errPos = pos },
.nixCode = NixCode { .errPos = pos }, });
});
} }
static void dupAttr(Symbol attr, const Pos & pos, const Pos & prevPos) static void dupAttr(Symbol attr, const Pos & pos, const Pos & prevPos)
{ {
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("attribute '%1%' already defined at %2%", attr, prevPos),
.hint = hintfmt("attribute '%1%' already defined at %2%", .nixCode = NixCode { .errPos = pos },
attr, prevPos), });
.nixCode = NixCode { .errPos = pos },
});
} }
@ -148,12 +145,11 @@ static void addAttr(ExprAttrs * attrs, AttrPath & attrPath,
static void addFormal(const Pos & pos, Formals * formals, const Formal & formal) static void addFormal(const Pos & pos, Formals * formals, const Formal & formal)
{ {
if (!formals->argNames.insert(formal.name).second) if (!formals->argNames.insert(formal.name).second)
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("duplicate formal function argument '%1%'",
.hint = hintfmt("duplicate formal function argument '%1%'", formal.name),
formal.name), .nixCode = NixCode { .errPos = pos },
.nixCode = NixCode { .errPos = pos }, });
});
formals->formals.push_front(formal); formals->formals.push_front(formal);
} }
@ -261,10 +257,10 @@ static inline Pos makeCurPos(const YYLTYPE & loc, ParseData * data)
void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * error) void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * error)
{ {
data->error = ErrorInfo { data->error = {
.hint = hintfmt(error), .hint = hintfmt(error),
.nixCode = NixCode { .errPos = makeCurPos(*loc, data) } .nixCode = NixCode { .errPos = makeCurPos(*loc, data) }
}; };
} }
@ -341,11 +337,10 @@ expr_function
{ $$ = new ExprWith(CUR_POS, $2, $4); } { $$ = new ExprWith(CUR_POS, $2, $4); }
| LET binds IN expr_function | LET binds IN expr_function
{ if (!$2->dynamicAttrs.empty()) { if (!$2->dynamicAttrs.empty())
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("dynamic attributes not allowed in let"),
.hint = hintfmt("dynamic attributes not allowed in let"), .nixCode = NixCode { .errPos = CUR_POS },
.nixCode = NixCode { .errPos = CUR_POS }, });
});
$$ = new ExprLet($2, $4); $$ = new ExprLet($2, $4);
} }
| expr_if | expr_if
@ -422,11 +417,10 @@ expr_simple
| URI { | URI {
static bool noURLLiterals = settings.isExperimentalFeatureEnabled("no-url-literals"); static bool noURLLiterals = settings.isExperimentalFeatureEnabled("no-url-literals");
if (noURLLiterals) if (noURLLiterals)
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("URL literals are disabled"),
.hint = hintfmt("URL literals are disabled"), .nixCode = NixCode { .errPos = CUR_POS }
.nixCode = NixCode { .errPos = CUR_POS } });
});
$$ = new ExprString(data->symbols.create($1)); $$ = new ExprString(data->symbols.create($1));
} }
| '(' expr ')' { $$ = $2; } | '(' expr ')' { $$ = $2; }
@ -496,11 +490,10 @@ attrs
$$->push_back(AttrName(str->s)); $$->push_back(AttrName(str->s));
delete str; delete str;
} else } else
throw ParseError( throw ParseError({
ErrorInfo { .hint = hintfmt("dynamic attributes not allowed in inherit"),
.hint = hintfmt("dynamic attributes not allowed in inherit"), .nixCode = NixCode { .errPos = makeCurPos(@2, data) },
.nixCode = NixCode { .errPos = makeCurPos(@2, data) }, });
});
} }
| { $$ = new AttrPath; } | { $$ = new AttrPath; }
; ;
@ -695,11 +688,10 @@ Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos
Path res = r.second + suffix; Path res = r.second + suffix;
if (pathExists(res)) return canonPath(res); if (pathExists(res)) return canonPath(res);
} }
throw ThrownError( throw ThrownError({
ErrorInfo { .hint = hintfmt("file '%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)", path),
.hint = hintfmt("file '%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)", path), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
@ -715,10 +707,9 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
res = { true, store->toRealPath(fetchers::downloadTarball( res = { true, store->toRealPath(fetchers::downloadTarball(
store, resolveUri(elem.second), "source", false).storePath) }; store, resolveUri(elem.second), "source", false).storePath) };
} catch (FileTransferError & e) { } catch (FileTransferError & e) {
logWarning( logWarning({
ErrorInfo { .name = "Entry download",
.name = "Entry download", .hint = hintfmt("Nix search path entry '%1%' cannot be downloaded, ignoring", elem.second)
.hint = hintfmt("Nix search path entry '%1%' cannot be downloaded, ignoring", elem.second)
}); });
res = { false, "" }; res = { false, "" };
} }
@ -727,10 +718,9 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
if (pathExists(path)) if (pathExists(path))
res = { true, path }; res = { true, path };
else { else {
logWarning( logWarning({
ErrorInfo { .name = "Entry not found",
.name = "Entry not found", .hint = hintfmt("warning: Nix search path entry '%1%' does not exist, ignoring", elem.second)
.hint = hintfmt("warning: Nix search path entry '%1%' does not exist, ignoring", elem.second)
}); });
res = { false, "" }; res = { false, "" };
} }

View file

@ -93,12 +93,10 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
try { try {
state.realiseContext(context); state.realiseContext(context);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("cannot import '%1%', since path '%2%' is not valid", path, e.path),
.hint = hintfmt("cannot import '%1%', since path '%2%' is not valid", .nixCode = NixCode { .errPos = pos }
path, e.path), });
.nixCode = NixCode { .errPos = pos }
});
} }
Path realPath = state.checkSourcePath(state.toRealPath(path, context)); Path realPath = state.checkSourcePath(state.toRealPath(path, context));
@ -174,13 +172,12 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
try { try {
state.realiseContext(context); state.realiseContext(context);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt(
.hint = hintfmt( "cannot import '%1%', since path '%2%' is not valid",
"cannot import '%1%', since path '%2%' is not valid", path, e.path),
path, e.path), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
path = state.checkSourcePath(path); path = state.checkSourcePath(path);
@ -215,11 +212,10 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
auto elems = args[0]->listElems(); auto elems = args[0]->listElems();
auto count = args[0]->listSize(); auto count = args[0]->listSize();
if (count == 0) { if (count == 0) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("at least one argument to 'exec' required"),
.hint = hintfmt("at least one argument to 'exec' required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
PathSet context; PathSet context;
auto program = state.coerceToString(pos, *elems[0], context, false, false); auto program = state.coerceToString(pos, *elems[0], context, false, false);
@ -230,12 +226,12 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
try { try {
state.realiseContext(context); state.realiseContext(context);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
.hint = hintfmt("cannot execute '%1%', since path '%2%' is not valid", program, e.path),
program, e.path), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});} }
auto output = runProgram(program, true, commandArgs); auto output = runProgram(program, true, commandArgs);
Expr * parsed; Expr * parsed;
@ -386,11 +382,10 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
Bindings::iterator startSet = Bindings::iterator startSet =
args[0]->attrs->find(state.symbols.create("startSet")); args[0]->attrs->find(state.symbols.create("startSet"));
if (startSet == args[0]->attrs->end()) if (startSet == args[0]->attrs->end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("attribute 'startSet' required"),
.hint = hintfmt("attribute 'startSet' required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.forceList(*startSet->value, pos); state.forceList(*startSet->value, pos);
ValueList workSet; ValueList workSet;
@ -401,11 +396,10 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
Bindings::iterator op = Bindings::iterator op =
args[0]->attrs->find(state.symbols.create("operator")); args[0]->attrs->find(state.symbols.create("operator"));
if (op == args[0]->attrs->end()) if (op == args[0]->attrs->end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("attribute 'operator' required"),
.hint = hintfmt("attribute 'operator' required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.forceValue(*op->value, pos); state.forceValue(*op->value, pos);
/* Construct the closure by applying the operator to element of /* Construct the closure by applying the operator to element of
@ -424,11 +418,10 @@ static void prim_genericClosure(EvalState & state, const Pos & pos, Value * * ar
Bindings::iterator key = Bindings::iterator key =
e->attrs->find(state.symbols.create("key")); e->attrs->find(state.symbols.create("key"));
if (key == e->attrs->end()) if (key == e->attrs->end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("attribute 'key' required"),
.hint = hintfmt("attribute 'key' required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.forceValue(*key->value, pos); state.forceValue(*key->value, pos);
if (!doneKeys.insert(key->value).second) continue; if (!doneKeys.insert(key->value).second) continue;
@ -560,11 +553,10 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
/* Figure out the name first (for stack backtraces). */ /* Figure out the name first (for stack backtraces). */
Bindings::iterator attr = args[0]->attrs->find(state.sName); Bindings::iterator attr = args[0]->attrs->find(state.sName);
if (attr == args[0]->attrs->end()) if (attr == args[0]->attrs->end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("required attribute 'name' missing"),
.hint = hintfmt("required attribute 'name' missing"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
string drvName; string drvName;
Pos & posDrvName(*attr->pos); Pos & posDrvName(*attr->pos);
try { try {
@ -608,41 +600,37 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive; if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive;
else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat; else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat;
else else
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
.hint = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
}; };
auto handleOutputs = [&](const Strings & ss) { auto handleOutputs = [&](const Strings & ss) {
outputs.clear(); outputs.clear();
for (auto & j : ss) { for (auto & j : ss) {
if (outputs.find(j) != outputs.end()) if (outputs.find(j) != outputs.end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("duplicate derivation output '%1%'", j),
.hint = hintfmt("duplicate derivation output '%1%'", j), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
/* !!! Check whether j is a valid attribute /* !!! Check whether j is a valid attribute
name. */ name. */
/* Derivations cannot be named drv, because /* Derivations cannot be named drv, because
then we'd have an attribute drvPath in then we'd have an attribute drvPath in
the resulting set. */ the resulting set. */
if (j == "drv") if (j == "drv")
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("invalid derivation output name 'drv'" ),
.hint = hintfmt("invalid derivation output name 'drv'" ), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
outputs.insert(j); outputs.insert(j);
} }
if (outputs.empty()) if (outputs.empty())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("derivation cannot have an empty set of outputs"),
.hint = hintfmt("derivation cannot have an empty set of outputs"), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
}; };
try { try {
@ -754,35 +742,31 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
/* Do we have all required attributes? */ /* Do we have all required attributes? */
if (drv.builder == "") if (drv.builder == "")
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("required attribute 'builder' missing"),
.hint = hintfmt("required attribute 'builder' missing"), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
if (drv.platform == "") if (drv.platform == "")
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("required attribute 'system' missing"),
.hint = hintfmt("required attribute 'system' missing"), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
/* Check whether the derivation name is valid. */ /* Check whether the derivation name is valid. */
if (isDerivation(drvName)) if (isDerivation(drvName))
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
.hint = hintfmt("derivation names are not allowed to end in '%s'", drvExtension), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
if (outputHash) { if (outputHash) {
/* Handle fixed-output derivations. */ /* Handle fixed-output derivations. */
if (outputs.size() != 1 || *(outputs.begin()) != "out") if (outputs.size() != 1 || *(outputs.begin()) != "out")
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("multiple outputs are not supported in fixed-output derivations"),
.hint = hintfmt("multiple outputs are not supported in fixed-output derivations"), .nixCode = NixCode { .errPos = posDrvName }
.nixCode = NixCode { .errPos = posDrvName } });
});
HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo); HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo);
@ -887,11 +871,10 @@ static void prim_storePath(EvalState & state, const Pos & pos, Value * * args, V
e.g. nix-push does the right thing. */ e.g. nix-push does the right thing. */
if (!state.store->isStorePath(path)) path = canonPath(path, true); if (!state.store->isStorePath(path)) path = canonPath(path, true);
if (!state.store->isInStore(path)) if (!state.store->isInStore(path))
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("path '%1%' is not in the Nix store", path),
.hint = hintfmt("path '%1%' is not in the Nix store", path), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
Path path2 = state.store->toStorePath(path); Path path2 = state.store->toStorePath(path);
if (!settings.readOnlyMode) if (!settings.readOnlyMode)
state.store->ensurePath(state.store->parseStorePath(path2)); state.store->ensurePath(state.store->parseStorePath(path2));
@ -907,13 +890,12 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
try { try {
state.realiseContext(context); state.realiseContext(context);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt(
.hint = hintfmt( "cannot check the existence of '%1%', since path '%2%' is not valid",
"cannot check the existence of '%1%', since path '%2%' is not valid", path, e.path),
path, e.path), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
try { try {
@ -956,13 +938,11 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
try { try {
state.realiseContext(context); state.realiseContext(context);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid" .nixCode = NixCode { .errPos = pos }
, path, e.path), });
.nixCode = NixCode { .errPos = pos } }
});
}
string s = readFile(state.checkSourcePath(state.toRealPath(path, context))); string s = readFile(state.checkSourcePath(state.toRealPath(path, context)));
if (s.find((char) 0) != string::npos) if (s.find((char) 0) != string::npos)
throw Error("the contents of the file '%1%' cannot be represented as a Nix string", path); throw Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
@ -989,11 +969,10 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
i = v2.attrs->find(state.symbols.create("path")); i = v2.attrs->find(state.symbols.create("path"));
if (i == v2.attrs->end()) if (i == v2.attrs->end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("attribute 'path' missing"),
.hint = hintfmt("attribute 'path' missing"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
PathSet context; PathSet context;
string path = state.coerceToString(pos, *i->value, context, false, false); string path = state.coerceToString(pos, *i->value, context, false, false);
@ -1001,12 +980,10 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
try { try {
state.realiseContext(context); state.realiseContext(context);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
.hint = hintfmt("cannot find '%1%', since path '%2%' is not valid", .nixCode = NixCode { .errPos = pos }
path, e.path), });
.nixCode = NixCode { .errPos = pos }
});
} }
searchPath.emplace_back(prefix, path); searchPath.emplace_back(prefix, path);
@ -1023,11 +1000,10 @@ static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Va
string type = state.forceStringNoCtx(*args[0], pos); string type = state.forceStringNoCtx(*args[0], pos);
HashType ht = parseHashType(type); HashType ht = parseHashType(type);
if (ht == htUnknown) if (ht == htUnknown)
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("unknown hash type '%1%'", type),
.hint = hintfmt("unknown hash type '%1%'", type), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
PathSet context; // discarded PathSet context; // discarded
Path p = state.coerceToPath(pos, *args[1], context); Path p = state.coerceToPath(pos, *args[1], context);
@ -1043,12 +1019,10 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val
try { try {
state.realiseContext(ctx); state.realiseContext(ctx);
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", path, e.path),
.hint = hintfmt("cannot read '%1%', since path '%2%' is not valid", .nixCode = NixCode { .errPos = pos }
path, e.path), });
.nixCode = NixCode { .errPos = pos }
});
} }
DirEntries entries = readDirectory(state.checkSourcePath(path)); DirEntries entries = readDirectory(state.checkSourcePath(path));
@ -1118,15 +1092,13 @@ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Valu
for (auto path : context) { for (auto path : context) {
if (path.at(0) != '/') if (path.at(0) != '/')
throw EvalError( throw EvalError( {
ErrorInfo { .hint = hintfmt(
.hint = 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, .nixCode = NixCode { .errPos = pos }
path), });
.nixCode = NixCode { .errPos = pos }
});
refs.insert(state.store->parseStorePath(path)); refs.insert(state.store->parseStorePath(path));
} }
@ -1194,21 +1166,19 @@ static void prim_filterSource(EvalState & state, const Pos & pos, Value * * args
PathSet context; PathSet context;
Path path = state.coerceToPath(pos, *args[1], context); Path path = state.coerceToPath(pos, *args[1], context);
if (!context.empty()) if (!context.empty())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("string '%1%' cannot refer to other paths", path),
.hint = hintfmt("string '%1%' cannot refer to other paths", path), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
if (args[0]->type != tLambda) if (args[0]->type != tLambda)
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt(
.hint = 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])), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, Hash(), v); addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, Hash(), v);
} }
@ -1228,12 +1198,10 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
PathSet context; PathSet context;
path = state.coerceToPath(*attr.pos, *attr.value, context); path = state.coerceToPath(*attr.pos, *attr.value, context);
if (!context.empty()) if (!context.empty())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("string '%1%' cannot refer to other paths", path),
.hint = hintfmt("string '%1%' cannot refer to other paths", .nixCode = NixCode { .errPos = *attr.pos }
path), });
.nixCode = NixCode { .errPos = *attr.pos }
});
} else if (attr.name == state.sName) } else if (attr.name == state.sName)
name = state.forceStringNoCtx(*attr.value, *attr.pos); name = state.forceStringNoCtx(*attr.value, *attr.pos);
else if (n == "filter") { else if (n == "filter") {
@ -1244,19 +1212,16 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
else if (n == "sha256") else if (n == "sha256")
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
else else
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("unsupported argument '%1%' to 'addPath'", attr.name),
.hint = hintfmt("unsupported argument '%1%' to 'addPath'", .nixCode = NixCode { .errPos = *attr.pos }
attr.name), });
.nixCode = NixCode { .errPos = *attr.pos }
});
} }
if (path.empty()) if (path.empty())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("'path' required"),
.hint = hintfmt("'path' required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
if (name.empty()) if (name.empty())
name = baseNameOf(path); name = baseNameOf(path);
@ -1314,11 +1279,10 @@ void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v)
// !!! Should we create a symbol here or just do a lookup? // !!! Should we create a symbol here or just do a lookup?
Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr)); Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr));
if (i == args[1]->attrs->end()) if (i == args[1]->attrs->end())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("attribute '%1%' missing", attr),
.hint = hintfmt("attribute '%1%' missing", attr), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
// !!! add to stack trace? // !!! add to stack trace?
if (state.countCalls && i->pos) state.attrSelects[*i->pos]++; if (state.countCalls && i->pos) state.attrSelects[*i->pos]++;
state.forceValue(*i->value, pos); state.forceValue(*i->value, pos);
@ -1398,22 +1362,20 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
Bindings::iterator j = v2.attrs->find(state.sName); Bindings::iterator j = v2.attrs->find(state.sName);
if (j == v2.attrs->end()) if (j == v2.attrs->end())
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt("'name' attribute missing in a call to 'listToAttrs'"),
.hint = hintfmt("'name' attribute missing in a call to 'listToAttrs'"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
string name = state.forceStringNoCtx(*j->value, pos); string name = state.forceStringNoCtx(*j->value, pos);
Symbol sym = state.symbols.create(name); Symbol sym = state.symbols.create(name);
if (seen.insert(sym).second) { if (seen.insert(sym).second) {
Bindings::iterator j2 = v2.attrs->find(state.symbols.create(state.sValue)); Bindings::iterator j2 = v2.attrs->find(state.symbols.create(state.sValue));
if (j2 == v2.attrs->end()) if (j2 == v2.attrs->end())
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt("'value' attribute missing in a call to 'listToAttrs'"),
.hint = hintfmt("'value' attribute missing in a call to 'listToAttrs'"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
v.attrs->push_back(Attr(sym, j2->value, j2->pos)); v.attrs->push_back(Attr(sym, j2->value, j2->pos));
} }
} }
@ -1486,11 +1448,10 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
{ {
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
if (args[0]->type != tLambda) if (args[0]->type != tLambda)
throw TypeError( throw TypeError({
ErrorInfo { .hint = hintfmt("'functionArgs' requires a function"),
.hint = hintfmt("'functionArgs' requires a function"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
if (!args[0]->lambda.fun->matchAttrs) { if (!args[0]->lambda.fun->matchAttrs) {
state.mkAttrs(v, 0); state.mkAttrs(v, 0);
@ -1543,11 +1504,10 @@ static void elemAt(EvalState & state, const Pos & pos, Value & list, int n, Valu
{ {
state.forceList(list, pos); state.forceList(list, pos);
if (n < 0 || (unsigned int) n >= list.listSize()) if (n < 0 || (unsigned int) n >= list.listSize())
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("list index %1% is out of bounds", n),
.hint = hintfmt("list index %1% is out of bounds", n), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.forceValue(*list.listElems()[n], pos); state.forceValue(*list.listElems()[n], pos);
v = *list.listElems()[n]; v = *list.listElems()[n];
} }
@ -1574,11 +1534,10 @@ static void prim_tail(EvalState & state, const Pos & pos, Value * * args, Value
{ {
state.forceList(*args[0], pos); state.forceList(*args[0], pos);
if (args[0]->listSize() == 0) if (args[0]->listSize() == 0)
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("'tail' called on an empty list"),
.hint = hintfmt("'tail' called on an empty list"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.mkList(v, args[0]->listSize() - 1); state.mkList(v, args[0]->listSize() - 1);
for (unsigned int n = 0; n < v.listSize(); ++n) for (unsigned int n = 0; n < v.listSize(); ++n)
@ -1720,12 +1679,10 @@ static void prim_genList(EvalState & state, const Pos & pos, Value * * args, Val
auto len = state.forceInt(*args[1], pos); auto len = state.forceInt(*args[1], pos);
if (len < 0) if (len < 0)
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("cannot create list of size %1%", len),
.hint = hintfmt("cannot create list of size %1%", len), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
state.mkList(v, len); state.mkList(v, len);
@ -1884,11 +1841,10 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
NixFloat f2 = state.forceFloat(*args[1], pos); NixFloat f2 = state.forceFloat(*args[1], pos);
if (f2 == 0) if (f2 == 0)
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("division by zero"),
.hint = hintfmt("division by zero"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
if (args[0]->type == tFloat || args[1]->type == tFloat) { if (args[0]->type == tFloat || args[1]->type == tFloat) {
mkFloat(v, state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos)); mkFloat(v, state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos));
@ -1897,11 +1853,10 @@ static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value &
NixInt i2 = state.forceInt(*args[1], pos); NixInt i2 = state.forceInt(*args[1], pos);
/* Avoid division overflow as it might raise SIGFPE. */ /* Avoid division overflow as it might raise SIGFPE. */
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1) if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("overflow in integer division"),
.hint = hintfmt("overflow in integer division"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
mkInt(v, i1 / i2); mkInt(v, i1 / i2);
} }
@ -1959,11 +1914,10 @@ static void prim_substring(EvalState & state, const Pos & pos, Value * * args, V
string s = state.coerceToString(pos, *args[2], context); string s = state.coerceToString(pos, *args[2], context);
if (start < 0) if (start < 0)
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("negative start position in 'substring'"),
.hint = hintfmt("negative start position in 'substring'"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
mkString(v, (unsigned int) start >= s.size() ? "" : string(s, start, len), context); mkString(v, (unsigned int) start >= s.size() ? "" : string(s, start, len), context);
} }
@ -1983,11 +1937,10 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
string type = state.forceStringNoCtx(*args[0], pos); string type = state.forceStringNoCtx(*args[0], pos);
HashType ht = parseHashType(type); HashType ht = parseHashType(type);
if (ht == htUnknown) if (ht == htUnknown)
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("unknown hash type '%1%'", type),
.hint = hintfmt("unknown hash type '%1%'", type), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
PathSet context; // discarded PathSet context; // discarded
string s = state.forceString(*args[1], context, pos); string s = state.forceString(*args[1], context, pos);
@ -2030,17 +1983,15 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
} catch (std::regex_error &e) { } catch (std::regex_error &e) {
if (e.code() == std::regex_constants::error_space) { if (e.code() == std::regex_constants::error_space) {
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++ // limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("memory limit exceeded by regular expression '%s'", re),
.hint = hintfmt("memory limit exceeded by regular expression '%s'", re), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} else { } else {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("invalid regular expression '%s'", re),
.hint = hintfmt("invalid regular expression '%s'", re), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
} }
} }
@ -2105,17 +2056,15 @@ static void prim_split(EvalState & state, const Pos & pos, Value * * args, Value
} catch (std::regex_error &e) { } catch (std::regex_error &e) {
if (e.code() == std::regex_constants::error_space) { if (e.code() == std::regex_constants::error_space) {
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++ // limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("memory limit exceeded by regular expression '%s'", re),
.hint = hintfmt("memory limit exceeded by regular expression '%s'", re), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} else { } else {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("invalid regular expression '%s'", re),
.hint = hintfmt("invalid regular expression '%s'", re), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
} }
} }
@ -2146,11 +2095,10 @@ static void prim_replaceStrings(EvalState & state, const Pos & pos, Value * * ar
state.forceList(*args[0], pos); state.forceList(*args[0], pos);
state.forceList(*args[1], pos); state.forceList(*args[1], pos);
if (args[0]->listSize() != args[1]->listSize()) if (args[0]->listSize() != args[1]->listSize())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
.hint = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
vector<string> from; vector<string> from;
from.reserve(args[0]->listSize()); from.reserve(args[0]->listSize());

View file

@ -146,11 +146,10 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
auto sAllOutputs = state.symbols.create("allOutputs"); auto sAllOutputs = state.symbols.create("allOutputs");
for (auto & i : *args[1]->attrs) { for (auto & i : *args[1]->attrs) {
if (!state.store->isStorePath(i.name)) if (!state.store->isStorePath(i.name))
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("Context key '%s' is not a store path", i.name),
.hint = hintfmt("Context key '%s' is not a store path", i.name), .nixCode = NixCode { .errPos = *i.pos }
.nixCode = NixCode { .errPos = *i.pos } });
});
if (!settings.readOnlyMode) if (!settings.readOnlyMode)
state.store->ensurePath(state.store->parseStorePath(i.name)); state.store->ensurePath(state.store->parseStorePath(i.name));
state.forceAttrs(*i.value, *i.pos); state.forceAttrs(*i.value, *i.pos);
@ -164,11 +163,10 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
if (iter != i.value->attrs->end()) { if (iter != i.value->attrs->end()) {
if (state.forceBool(*iter->value, *iter->pos)) { if (state.forceBool(*iter->value, *iter->pos)) {
if (!isDerivation(i.name)) { if (!isDerivation(i.name)) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("Tried to add all-outputs context of %s, which is not a derivation, to a string", i.name),
.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 }
.nixCode = NixCode { .errPos = *i.pos } });
});
} }
context.insert("=" + string(i.name)); context.insert("=" + string(i.name));
} }
@ -178,11 +176,10 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
if (iter != i.value->attrs->end()) { if (iter != i.value->attrs->end()) {
state.forceList(*iter->value, *iter->pos); state.forceList(*iter->value, *iter->pos);
if (iter->value->listSize() && !isDerivation(i.name)) { if (iter->value->listSize() && !isDerivation(i.name)) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("Tried to add derivation output context of %s, which is not a derivation, to a string", i.name),
.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 }
.nixCode = NixCode { .errPos = *i.pos } });
});
} }
for (unsigned int n = 0; n < iter->value->listSize(); ++n) { for (unsigned int n = 0; n < iter->value->listSize(); ++n) {
auto name = state.forceStringNoCtx(*iter->value->listElems()[n], *iter->pos); auto name = state.forceStringNoCtx(*iter->value->listElems()[n], *iter->pos);

View file

@ -35,19 +35,17 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va
else if (n == "submodules") else if (n == "submodules")
fetchSubmodules = state.forceBool(*attr.value, *attr.pos); fetchSubmodules = state.forceBool(*attr.value, *attr.pos);
else else
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("unsupported argument '%s' to 'fetchGit'", attr.name),
.hint = hintfmt("unsupported argument '%s' to 'fetchGit'", attr.name), .nixCode = NixCode { .errPos = *attr.pos }
.nixCode = NixCode { .errPos = *attr.pos } });
});
} }
if (url.empty()) if (url.empty())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("'url' argument required"),
.hint = hintfmt("'url' argument required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} else } else
url = state.coerceToString(pos, *args[0], context, false, false); url = state.coerceToString(pos, *args[0], context, false, false);

View file

@ -38,19 +38,17 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
else if (n == "name") else if (n == "name")
name = state.forceStringNoCtx(*attr.value, *attr.pos); name = state.forceStringNoCtx(*attr.value, *attr.pos);
else else
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("unsupported argument '%s' to 'fetchMercurial'", attr.name),
.hint = hintfmt("unsupported argument '%s' to 'fetchMercurial'", attr.name), .nixCode = NixCode { .errPos = *attr.pos }
.nixCode = NixCode { .errPos = *attr.pos } });
});
} }
if (url.empty()) if (url.empty())
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("'url' argument required"),
.hint = hintfmt("'url' argument required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} else } else
url = state.coerceToString(pos, *args[0], context, false, false); url = state.coerceToString(pos, *args[0], context, false, false);

View file

@ -66,11 +66,10 @@ static void prim_fetchTree(EvalState & state, const Pos & pos, Value * * args, V
} }
if (!attrs.count("type")) if (!attrs.count("type"))
throw Error( throw Error({
ErrorInfo { .hint = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
.hint = hintfmt("attribute 'type' is missing in call to 'fetchTree'"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
input = fetchers::inputFromAttrs(attrs); input = fetchers::inputFromAttrs(attrs);
} else } else
@ -111,20 +110,17 @@ static void fetch(EvalState & state, const Pos & 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
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("unsupported argument '%s' to '%s'", attr.name, who),
.hint = hintfmt("unsupported argument '%s' to '%s'", .nixCode = NixCode { .errPos = *attr.pos }
attr.name, who), });
.nixCode = NixCode { .errPos = *attr.pos }
});
} }
if (!url) if (!url)
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("'url' argument required"),
.hint = hintfmt("'url' argument required"), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} else } else
url = state.forceStringNoCtx(*args[0], pos); url = state.forceStringNoCtx(*args[0], pos);

View file

@ -81,11 +81,10 @@ static void prim_fromTOML(EvalState & state, const Pos & pos, Value * * args, Va
try { try {
visit(v, parser(tomlStream).parse()); visit(v, parser(tomlStream).parse());
} catch (std::runtime_error & e) { } catch (std::runtime_error & e) {
throw EvalError( throw EvalError({
ErrorInfo { .hint = hintfmt("while parsing a TOML string: %s", e.what()),
.hint = hintfmt("while parsing a TOML string: %s", e.what()), .nixCode = NixCode { .errPos = pos }
.nixCode = NixCode { .errPos = pos } });
});
} }
} }

View file

@ -22,10 +22,9 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
srcFiles = readDirectory(srcDir); srcFiles = readDirectory(srcDir);
} catch (SysError & e) { } catch (SysError & e) {
if (e.errNo == ENOTDIR) { if (e.errNo == ENOTDIR) {
logWarning( logWarning({
ErrorInfo { .name = "Create links - directory",
.name = "Create links - directory", .hint = hintfmt("not including '%s' in the user environment because it's not a directory", srcDir)
.hint = hintfmt("not including '%s' in the user environment because it's not a directory", srcDir)
}); });
return; return;
} }
@ -45,10 +44,9 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
throw SysError("getting status of '%1%'", srcFile); throw SysError("getting status of '%1%'", srcFile);
} catch (SysError & e) { } catch (SysError & e) {
if (e.errNo == ENOENT || e.errNo == ENOTDIR) { if (e.errNo == ENOENT || e.errNo == ENOTDIR) {
logWarning( logWarning({
ErrorInfo { .name = "Create links - skipping symlink",
.name = "Create links - skipping symlink", .hint = hintfmt("skipping dangling symlink '%s'", dstFile)
.hint = hintfmt("skipping dangling symlink '%s'", dstFile)
}); });
continue; continue;
} }

View file

@ -129,12 +129,11 @@ Path LocalFSStore::addPermRoot(const StorePath & storePath,
if (settings.checkRootReachability) { if (settings.checkRootReachability) {
auto roots = findRoots(false); auto roots = findRoots(false);
if (roots[storePath.clone()].count(gcRoot) == 0) if (roots[storePath.clone()].count(gcRoot) == 0)
logWarning( logWarning({
ErrorInfo { .name = "GC root",
.name = "GC root", .hint = hintfmt("warning: '%1%' is not in a directory where the garbage collector looks for roots; "
.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",
"therefore, '%2%' might be removed by the garbage collector", gcRoot, printStorePath(storePath))
gcRoot, printStorePath(storePath))
}); });
} }

View file

@ -204,10 +204,10 @@ void handleSQLiteBusy(const SQLiteBusy & e)
if (now > lastWarned + 10) { if (now > lastWarned + 10) {
lastWarned = now; lastWarned = now;
logWarning( logWarning({
ErrorInfo { .name = "Sqlite busy", .name = "Sqlite busy",
.hint = hintfmt(e.what()) .hint = hintfmt(e.what())
}); });
} }
/* Sleep for a while since retrying the transaction right away /* Sleep for a while since retrying the transaction right away

View file

@ -119,9 +119,9 @@ public:
{ } { }
template<typename... Args> template<typename... Args>
BaseError(const Args & ... args) BaseError(const std::string & fs, const Args & ... args)
: err { .level = lvlError, : 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) : err(e)
{ } { }

View file

@ -52,10 +52,10 @@ size_t threshold = 256 * 1024 * 1024;
static void warnLargeDump() static void warnLargeDump()
{ {
logWarning(ErrorInfo { logWarning({
.name = "Large path", .name = "Large path",
.description = "dumping very large path (> 256 MiB); this may run out of memory" .description = "dumping very large path (> 256 MiB); this may run out of memory"
}); });
} }

View file

@ -368,12 +368,11 @@ static void _main(int argc, char * * argv)
shell = drv->queryOutPath() + "/bin/bash"; shell = drv->queryOutPath() + "/bin/bash";
} catch (Error & e) { } catch (Error & e) {
logWarning( logWarning({
ErrorInfo { .name = "bashInteractive",
.name = "bashInteractive", .hint = hintfmt("%s; will use bash from your environment",
.hint = hintfmt("%s; will use bash from your environment", (e.info().hint ? e.info().hint->str() : ""))
(e.info().hint ? e.info().hint->str() : "")) });
});
shell = "bash"; shell = "bash";
} }
} }

View file

@ -68,10 +68,9 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
if (dryRun) { if (dryRun) {
stopProgressBar(); stopProgressBar();
logWarning( logWarning({
ErrorInfo { .name = "Version update",
.name = "Version update", .hint = hintfmt("would upgrade to version %s", version)
.hint = hintfmt("would upgrade to version %s", version)
}); });
return; return;
} }