convert some errors

This commit is contained in:
Ben Burdette 2020-05-01 14:32:06 -06:00
parent a3030e3c31
commit 4b99c09f5c
7 changed files with 86 additions and 22 deletions

View file

@ -22,7 +22,11 @@ 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) {
printError("warning: not including '%s' in the user environment because it's not a directory", srcDir); logWarning(
ErrorInfo {
.name = "Create Links - Directory",
.hint = hintfmt("not including '%s' in the user environment because it's not a directory", srcDir)
});
return; return;
} }
throw; throw;
@ -41,7 +45,11 @@ 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) {
printError("warning: skipping dangling symlink '%s'", dstFile); logWarning(
ErrorInfo {
.name = "Create Links - Skipping Symlink",
.hint = hintfmt("skipping dangling symlink '%s'", dstFile)
});
continue; continue;
} }
throw; throw;

View file

@ -600,7 +600,12 @@ struct CurlDownloader : public Downloader
workerThreadMain(); workerThreadMain();
} catch (nix::Interrupted & e) { } catch (nix::Interrupted & e) {
} catch (std::exception & e) { } catch (std::exception & e) {
printError("unexpected error in download thread: %s", e.what()); logError(
ErrorInfo {
.name = "download",
.hint = hintfmt("unexpected error in download thread: %s",
e.what())
});
} }
{ {

View file

@ -41,7 +41,8 @@ AutoCloseFD LocalStore::openGCLock(LockType lockType)
throw SysError("opening global GC lock '%1%'", fnGCLock); throw SysError("opening global GC lock '%1%'", fnGCLock);
if (!lockFile(fdGCLock.get(), lockType, false)) { if (!lockFile(fdGCLock.get(), lockType, false)) {
printError(format("waiting for the big garbage collector lock...")); // TODO: info?
printError("waiting for the big garbage collector lock...");
lockFile(fdGCLock.get(), lockType, true); lockFile(fdGCLock.get(), lockType, true);
} }
@ -129,10 +130,14 @@ 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)
printError(
"warning: '%1%' is not in a directory where the garbage collector looks for roots; " logWarning(
ErrorInfo {
.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", "therefore, '%2%' might be removed by the garbage collector",
gcRoot, printStorePath(storePath)); gcRoot, printStorePath(storePath))
});
} }
/* Grab the global GC root, causing us to block while a GC is in /* Grab the global GC root, causing us to block while a GC is in

View file

@ -87,8 +87,13 @@ LocalStore::LocalStore(const Params & params)
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str()); struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
if (!gr) if (!gr)
printError(format("warning: the group '%1%' specified in 'build-users-group' does not exist") logError(
% settings.buildUsersGroup); ErrorInfo {
.name = "'build-users-group' not found",
.hint = hintfmt(
"warning: the group '%1%' specified in 'build-users-group' does not exist",
settings.buildUsersGroup)
});
else { else {
struct stat st; struct stat st;
if (stat(realStoreDir.c_str(), &st)) if (stat(realStoreDir.c_str(), &st))
@ -876,7 +881,7 @@ void LocalStore::querySubstitutablePathInfos(const StorePathSet & paths,
} catch (SubstituterDisabled &) { } catch (SubstituterDisabled &) {
} catch (Error & e) { } catch (Error & e) {
if (settings.tryFallback) if (settings.tryFallback)
printError(e.what()); logError(e.info());
else else
throw; throw;
} }
@ -1237,9 +1242,13 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
Path linkPath = linksDir + "/" + link.name; Path linkPath = linksDir + "/" + link.name;
string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false); string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false);
if (hash != link.name) { if (hash != link.name) {
printError( logError(
ErrorInfo {
.name = "Invalid Hash",
.hint = hintfmt(
"link '%s' was modified! expected hash '%s', got '%s'", "link '%s' was modified! expected hash '%s', got '%s'",
linkPath, link.name, hash); linkPath, link.name, hash)
});
if (repair) { if (repair) {
if (unlink(linkPath.c_str()) == 0) if (unlink(linkPath.c_str()) == 0)
printError("removed link '%s'", linkPath); printError("removed link '%s'", linkPath);
@ -1272,8 +1281,12 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
auto current = hashSink->finish(); auto current = hashSink->finish();
if (info->narHash != nullHash && info->narHash != current.first) { if (info->narHash != nullHash && info->narHash != current.first) {
printError("path '%s' was modified! expected hash '%s', got '%s'", logError(
printStorePath(i), info->narHash.to_string(), current.first.to_string()); ErrorInfo {
.name = "Invalid Hash - Path Modified",
.hint = hintfmt("path '%s' was modified! expected hash '%s', got '%s'",
printStorePath(i), info->narHash.to_string(), current.first.to_string())
});
if (repair) repairPath(i); else errors = true; if (repair) repairPath(i); else errors = true;
} else { } else {
@ -1304,7 +1317,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
/* It's possible that the path got GC'ed, so ignore /* It's possible that the path got GC'ed, so ignore
errors on invalid paths. */ errors on invalid paths. */
if (isValidPath(i)) if (isValidPath(i))
printError("error: %s", e.msg()); logError(e.info());
else else
warn(e.msg()); warn(e.msg());
errors = true; errors = true;
@ -1324,7 +1337,11 @@ void LocalStore::verifyPath(const Path & pathS, const StringSet & store,
if (!done.insert(pathS).second) return; if (!done.insert(pathS).second) return;
if (!isStorePath(pathS)) { if (!isStorePath(pathS)) {
printError("path '%s' is not in the Nix store", pathS); logError(
ErrorInfo {
.name = "Nix path not found",
.hint = hintfmt("path '%s' is not in the Nix store", pathS)
});
return; return;
} }
@ -1347,12 +1364,17 @@ void LocalStore::verifyPath(const Path & pathS, const StringSet & store,
auto state(_state.lock()); auto state(_state.lock());
invalidatePath(*state, path); invalidatePath(*state, path);
} else { } else {
printError("path '%s' disappeared, but it still has valid referrers!", pathS); // TODO log as warning if repair successful??
logError(
ErrorInfo {
.name = "Missing path with referrers",
.hint = hintfmt("path '%s' disappeared, but it still has valid referrers!", pathS)
});
if (repair) if (repair)
try { try {
repairPath(path); repairPath(path);
} catch (Error & e) { } catch (Error & e) {
warn(e.msg()); logWarning(e.info());
errors = true; errors = true;
} }
else errors = true; else errors = true;

View file

@ -130,7 +130,11 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
NixOS (example: $fontconfig/var/cache being modified). Skip NixOS (example: $fontconfig/var/cache being modified). Skip
those files. FIXME: check the modification time. */ those files. FIXME: check the modification time. */
if (S_ISREG(st.st_mode) && (st.st_mode & S_IWUSR)) { if (S_ISREG(st.st_mode) && (st.st_mode & S_IWUSR)) {
printError("skipping suspicious writable file '%1%'", path); logWarning(
ErrorInfo {
.name = "Suspicious File",
.hint = hintfmt("skipping suspicious writable file '%1%'", path)
});
return; return;
} }
@ -194,7 +198,11 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
} }
if (st.st_size != stLink.st_size) { if (st.st_size != stLink.st_size) {
printError("removing corrupted link '%1%'", linkPath); logWarning(
ErrorInfo {
.name = "Corrupted Link",
.hint = hintfmt("removing corrupted link '%1%'", linkPath)
});
unlink(linkPath.c_str()); unlink(linkPath.c_str());
goto retry; goto retry;
} }
@ -229,7 +237,11 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
/* Atomically replace the old file with the new hard link. */ /* Atomically replace the old file with the new hard link. */
if (rename(tempLink.c_str(), path.c_str()) == -1) { if (rename(tempLink.c_str(), path.c_str()) == -1) {
if (unlink(tempLink.c_str()) == -1) if (unlink(tempLink.c_str()) == -1)
printError("unable to unlink '%1%'", tempLink); logError(
ErrorInfo {
.name = "Unlink error",
.hint = hintfmt("unable to unlink '%1%'", tempLink)
});
if (errno == EMLINK) { if (errno == EMLINK) {
/* Some filesystems generate too many links on the rename, /* Some filesystems generate too many links on the rename,
rather than on the original link. (Probably it rather than on the original link. (Probably it

View file

@ -780,6 +780,15 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source *
} }
else if (msg == STDERR_NEXT) else if (msg == STDERR_NEXT)
// TODO: is this really an ErrorInfo error? Seems like we're forwarding the
// stderr output of the remote to current stderr/log
// ErrorInfo gets lost in this scenario.
// An alternative might be a logger on the remote that forwards ErrorInfo and etc.
// logError(
// ErrorInfo {
// // .name = "Remote Store" TODO reasonable name.
// .hint = hintfmt(chomp(readString(from)))
// });
printError(chomp(readString(from))); printError(chomp(readString(from)));
else if (msg == STDERR_START_ACTIVITY) { else if (msg == STDERR_START_ACTIVITY) {

View file

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