formatting and a few minor changes

This commit is contained in:
Ben Burdette 2020-05-13 15:56:39 -06:00
parent d44bac1d92
commit ef9dd9f9bc
13 changed files with 54 additions and 77 deletions

View file

@ -427,7 +427,6 @@ expr_simple
.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; }
@ -696,7 +695,6 @@ 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 { 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),

View file

@ -99,7 +99,6 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
path, e.path), path, e.path),
.nixCode = NixCode { .errPos = pos } .nixCode = NixCode { .errPos = pos }
}); });
} }
Path realPath = state.checkSourcePath(state.toRealPath(path, context)); Path realPath = state.checkSourcePath(state.toRealPath(path, context));
@ -179,7 +178,7 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
ErrorInfo { 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 }
}); });
} }
@ -199,8 +198,8 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
if (message) if (message)
throw EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message); throw EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message);
else else
throw EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected" throw EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected",
, sym, path); sym, path);
} }
(func)(state, v); (func)(state, v);
@ -233,8 +232,8 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
} catch (InvalidPathError & e) { } catch (InvalidPathError & e) {
throw EvalError( throw EvalError(
ErrorInfo { 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 }
});} });}
@ -625,8 +624,6 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
.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
@ -638,7 +635,6 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
.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())
@ -1236,7 +1232,6 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
path), path),
.nixCode = NixCode { .errPos = *attr.pos } .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") {
@ -1322,7 +1317,6 @@ void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v)
.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);
@ -1407,7 +1401,6 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
.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);
@ -1419,7 +1412,6 @@ static void prim_listToAttrs(EvalState & state, const Pos & pos, Value * * args,
.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));
} }
} }
@ -1498,7 +1490,6 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args
.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);
return; return;
@ -2038,16 +2029,16 @@ void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
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 { 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 { ErrorInfo {
.hint = hintfmt("invalid regular expression '%s'", re), .hint = hintfmt("invalid regular expression '%s'", re),
.nixCode = NixCode { .errPos = pos } .nixCode = NixCode { .errPos = pos }
}); });
} }
} }
} }
@ -2111,19 +2102,19 @@ 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 { 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 { ErrorInfo {
.hint = hintfmt("invalid regular expression '%s'", re), .hint = hintfmt("invalid regular expression '%s'", re),
.nixCode = NixCode { .errPos = pos } .nixCode = NixCode { .errPos = pos }
}); });
} }
} }
} }

View file

@ -151,7 +151,6 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
.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);
@ -170,7 +169,6 @@ static void prim_appendContext(EvalState & state, const Pos & pos, Value * * arg
.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));
} }

View file

@ -43,7 +43,6 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
.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())

View file

@ -497,8 +497,8 @@ void handleDiffHook(
printError(chomp(diffRes.second)); printError(chomp(diffRes.second));
} catch (Error & error) { } catch (Error & error) {
ErrorInfo ei = error.info(); ErrorInfo ei = error.info();
string prevhint = (error.info().hint.has_value() ? error.info().hint->str() : ""); ei.hint = hintfmt("diff hook execution failed: %s",
ei.hint = std::optional(hintfmt("diff hook execution failed: %s", prevhint)); (error.info().hint.has_value() ? error.info().hint->str() : ""));
logError(ei); logError(ei);
} }
} }
@ -1151,7 +1151,7 @@ void DerivationGoal::loadDerivation()
if (nrFailed != 0) { if (nrFailed != 0) {
logError( logError(
ErrorInfo { ErrorInfo {
.name = "missing derivation during build", .name = "missing derivation during build",
.hint = hintfmt("cannot build missing derivation '%s'", worker.store.printStorePath(drvPath)) .hint = hintfmt("cannot build missing derivation '%s'", worker.store.printStorePath(drvPath))
}); });
@ -1306,13 +1306,12 @@ void DerivationGoal::repairClosure()
for (auto & i : outputClosure) { for (auto & i : outputClosure) {
if (worker.pathContentsGood(i)) continue; if (worker.pathContentsGood(i)) continue;
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Corrupt path in closure", .name = "Corrupt path in closure",
.hint = hintfmt( .hint = hintfmt(
"found corrupted or missing path '%s' in the output closure of '%s'", "found corrupted or missing path '%s' in the output closure of '%s'",
worker.store.printStorePath(i), worker.store.printStorePath(drvPath)) worker.store.printStorePath(i), worker.store.printStorePath(drvPath))
}); });
auto drvPath2 = outputsToDrv.find(i); auto drvPath2 = outputsToDrv.find(i);
if (drvPath2 == outputsToDrv.end()) if (drvPath2 == outputsToDrv.end())
addWaitee(worker.makeSubstitutionGoal(i, Repair)); addWaitee(worker.makeSubstitutionGoal(i, Repair));
@ -1347,7 +1346,7 @@ void DerivationGoal::inputsRealised()
if (!useDerivation) if (!useDerivation)
throw Error("some dependencies of '%s' are missing", worker.store.printStorePath(drvPath)); throw Error("some dependencies of '%s' are missing", worker.store.printStorePath(drvPath));
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Dependencies could not be built", .name = "Dependencies could not be built",
.hint = hintfmt( .hint = hintfmt(
"cannot build derivation '%s': %s dependencies couldn't be built", "cannot build derivation '%s': %s dependencies couldn't be built",
@ -1811,7 +1810,7 @@ HookReply DerivationGoal::tryBuildHook()
} catch (SysError & e) { } catch (SysError & e) {
if (e.errNo == EPIPE) { if (e.errNo == EPIPE) {
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Build hook died", .name = "Build hook died",
.hint = hintfmt( .hint = hintfmt(
"build hook died unexpectedly: %s", "build hook died unexpectedly: %s",
@ -3676,7 +3675,7 @@ void DerivationGoal::registerOutputs()
if (!outputRewrites.empty()) { if (!outputRewrites.empty()) {
logWarning( logWarning(
ErrorInfo { ErrorInfo {
.name = "Rewriting hashes", .name = "Rewriting hashes",
.hint = hintfmt("rewriting hashes in '%1%'; cross fingers", path) .hint = hintfmt("rewriting hashes in '%1%'; cross fingers", path)
}); });
@ -3856,7 +3855,7 @@ void DerivationGoal::registerOutputs()
throw NotDeterministic(hint); throw NotDeterministic(hint);
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Output determinism error", .name = "Output determinism error",
.hint = hint .hint = hint
}); });
@ -4124,7 +4123,7 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
logSize += data.size(); logSize += data.size();
if (settings.maxLogSize && logSize > settings.maxLogSize) { if (settings.maxLogSize && logSize > settings.maxLogSize) {
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Max log size exceeded", .name = "Max log size exceeded",
.hint = hintfmt( .hint = hintfmt(
"%1% killed after writing more than %2% bytes of log output", "%1% killed after writing more than %2% bytes of log output",
@ -4447,9 +4446,9 @@ void SubstitutionGoal::tryNext()
{ {
logWarning( logWarning(
ErrorInfo { ErrorInfo {
.name = "Invalid path signature", .name = "Invalid path signature",
.hint = hintfmt("substituter '%s' does not have a valid signature for path '%s'", .hint = hintfmt("substituter '%s' does not have a valid signature for path '%s'",
sub->getUri(), worker.store.printStorePath(storePath)) sub->getUri(), worker.store.printStorePath(storePath))
}); });
tryNext(); tryNext();
return; return;
@ -4809,7 +4808,7 @@ void Worker::run(const Goals & _topGoals)
if (!children.empty() || !waitingForAWhile.empty()) if (!children.empty() || !waitingForAWhile.empty())
waitForInput(); waitForInput();
else { else {
if (awake.empty() && 0 == settings.maxBuildJobs) if (awake.empty() && 0 == settings.maxBuildJobs)
throw Error("unable to start any build; either increase '--max-jobs' " throw Error("unable to start any build; either increase '--max-jobs' "
"or enable remote builds"); "or enable remote builds");
assert(!awake.empty()); assert(!awake.empty());
@ -4933,7 +4932,7 @@ void Worker::waitForInput()
after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime)) after - j->lastOutput >= std::chrono::seconds(settings.maxSilentTime))
{ {
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Silent build timeout", .name = "Silent build timeout",
.hint = hintfmt( .hint = hintfmt(
"%1% timed out after %2% seconds of silence", "%1% timed out after %2% seconds of silence",
@ -4948,7 +4947,7 @@ void Worker::waitForInput()
after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout)) after - j->timeStarted >= std::chrono::seconds(settings.buildTimeout))
{ {
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Build timeout", .name = "Build timeout",
.hint = hintfmt( .hint = hintfmt(
"%1% timed out after %2% seconds", "%1% timed out after %2% seconds",
@ -4969,9 +4968,6 @@ void Worker::waitForInput()
} }
unsigned int Worker::exitStatus() unsigned int Worker::exitStatus()
{ {
/* /*
@ -5015,9 +5011,9 @@ bool Worker::pathContentsGood(const StorePath & path)
res = info->narHash == nullHash || info->narHash == current.first; res = info->narHash == nullHash || info->narHash == current.first;
} }
pathContentsGoodCache.insert_or_assign(path.clone(), res); pathContentsGoodCache.insert_or_assign(path.clone(), res);
if (!res) if (!res)
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Corrupted path", .name = "Corrupted path",
.hint = hintfmt("path '%s' is corrupted or missing!", store.printStorePath(path)) .hint = hintfmt("path '%s' is corrupted or missing!", store.printStorePath(path))
}); });
@ -5136,8 +5132,4 @@ void LocalStore::repairPath(const StorePath & path)
} }
} }

View file

@ -129,7 +129,6 @@ 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 { ErrorInfo {
.name = "GC root", .name = "GC root",

View file

@ -504,7 +504,7 @@ static void canonicalisePathMetaData_(const Path & path, uid_t fromUid, InodesSe
chown(path.c_str(), geteuid(), getegid()) == -1) chown(path.c_str(), geteuid(), getegid()) == -1)
#endif #endif
throw SysError("changing owner of '%1%' to %2%", throw SysError("changing owner of '%1%' to %2%",
path, geteuid()); path, geteuid());
} }
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {

View file

@ -196,7 +196,7 @@ SQLiteTxn::~SQLiteTxn()
} }
} }
void handleSQLiteBusy(SQLiteBusy & e) void handleSQLiteBusy(const SQLiteBusy & e)
{ {
static std::atomic<time_t> lastWarned{0}; static std::atomic<time_t> lastWarned{0};

View file

@ -99,7 +99,7 @@ MakeError(SQLiteBusy, SQLiteError);
[[noreturn]] void throwSQLiteError(sqlite3 * db, const FormatOrString & fs); [[noreturn]] void throwSQLiteError(sqlite3 * db, const FormatOrString & fs);
void handleSQLiteBusy(SQLiteBusy & e); void handleSQLiteBusy(const SQLiteBusy & e);
/* Convenience function for retrying a SQLite transaction when the /* Convenience function for retrying a SQLite transaction when the
database is busy. */ database is busy. */

View file

@ -15,13 +15,13 @@ using std::set;
using std::vector; using std::vector;
using std::string; using std::string;
typedef list<std::string> Strings; typedef list<string> Strings;
typedef set<std::string> StringSet; typedef set<string> StringSet;
typedef std::map<std::string, std::string> StringMap; typedef std::map<string, string> StringMap;
/* Paths are just strings. */ /* Paths are just strings. */
typedef std::string Path; typedef string Path;
typedef list<Path> Paths; typedef list<Path> Paths;
typedef set<Path> PathSet; typedef set<Path> PathSet;

View file

@ -248,8 +248,8 @@ static void daemonLoop(char * * argv)
return; return;
} catch (Error & error) { } catch (Error & error) {
ErrorInfo ei = error.info(); ErrorInfo ei = error.info();
string prevhint = (error.info().hint.has_value() ? error.info().hint->str() : ""); ei.hint = std::optional(hintfmt("error processing connection: %1%",
ei.hint = std::optional(hintfmt("error processing connection: %1%", prevhint)); (error.info().hint.has_value() ? error.info().hint->str() : "")));
logError(ei); logError(ei);
} }
} }

View file

@ -69,7 +69,7 @@ typedef void (* Operation) (Globals & globals,
static string needArg(Strings::iterator & i, static string needArg(Strings::iterator & i,
Strings & args, const string & arg) Strings & args, const string & arg)
{ {
if (i == args.end()) throw UsageError( "'%1%' requires an argument", arg); if (i == args.end()) throw UsageError("'%1%' requires an argument", arg);
return *i++; return *i++;
} }
@ -151,7 +151,7 @@ static void loadSourceExpr(EvalState & state, const Path & path, Value & v)
{ {
struct stat st; struct stat st;
if (stat(path.c_str(), &st) == -1) if (stat(path.c_str(), &st) == -1)
throw SysError("getting inon about '%1%'", path); throw SysError("getting information about '%1%'", path);
if (isNixExpr(path, st)) if (isNixExpr(path, st))
state.evalFile(path, v); state.evalFile(path, v);
@ -1233,7 +1233,7 @@ static void switchGeneration(Globals & globals, int dstGen)
if (!dst) { if (!dst) {
if (dstGen == prevGen) if (dstGen == prevGen)
throw Error("no generation older than the current (%1%) exists", throw Error("no generation older than the current (%1%) exists",
curGen); curGen);
else else
throw Error("generation %1% does not exist", dstGen); throw Error("generation %1% does not exist", dstGen);
} }

View file

@ -731,7 +731,7 @@ static void opVerifyPath(Strings opFlags, Strings opArgs)
if (current.first != info->narHash) { if (current.first != info->narHash) {
logError( logError(
ErrorInfo { ErrorInfo {
.name = "Hash match error", .name = "Hash mismatch",
.hint = hintfmt( .hint = hintfmt(
"path '%s' was modified! expected hash '%s', got '%s'", "path '%s' was modified! expected hash '%s', got '%s'",
store->printStorePath(path), store->printStorePath(path),