aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-06-15 11:46:31 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-06-15 11:46:31 +0200
commit7a77762961aee116e7179ea57f07e143d74aba1f (patch)
tree40d20ab8f8096bdfb662baf5c96e6725aadd4020 /src/nix
parent25d64f3a30e4fe224224d0c0470204215f7e570c (diff)
parentef1b3f21b6e51007d82e8e894dd9ecec0d1c5207 (diff)
Merge branch 'errors-phase-2' of https://github.com/bburdette/nix
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/cat.cc4
-rw-r--r--src/nix/hash.cc2
-rw-r--r--src/nix/ls.cc2
-rw-r--r--src/nix/make-content-addressable.cc2
-rw-r--r--src/nix/repl.cc8
-rw-r--r--src/nix/run.cc4
-rw-r--r--src/nix/upgrade-nix.cc8
-rw-r--r--src/nix/verify.cc23
8 files changed, 33 insertions, 20 deletions
diff --git a/src/nix/cat.cc b/src/nix/cat.cc
index fd91f2036..c82819af8 100644
--- a/src/nix/cat.cc
+++ b/src/nix/cat.cc
@@ -13,9 +13,9 @@ struct MixCat : virtual Args
{
auto st = accessor->stat(path);
if (st.type == FSAccessor::Type::tMissing)
- throw Error(format("path '%1%' does not exist") % path);
+ throw Error("path '%1%' does not exist", path);
if (st.type != FSAccessor::Type::tRegular)
- throw Error(format("path '%1%' is not a regular file") % path);
+ throw Error("path '%1%' is not a regular file", path);
std::cout << accessor->readFile(path);
}
diff --git a/src/nix/hash.cc b/src/nix/hash.cc
index 0a7c343d0..0dd4998d9 100644
--- a/src/nix/hash.cc
+++ b/src/nix/hash.cc
@@ -133,7 +133,7 @@ static int compatNixHash(int argc, char * * argv)
string s = getArg(*arg, arg, end);
ht = parseHashType(s);
if (ht == htUnknown)
- throw UsageError(format("unknown hash type '%1%'") % s);
+ throw UsageError("unknown hash type '%1%'", s);
}
else if (*arg == "--to-base16") op = opTo16;
else if (*arg == "--to-base32") op = opTo32;
diff --git a/src/nix/ls.cc b/src/nix/ls.cc
index b9716a6a1..d2157f2d4 100644
--- a/src/nix/ls.cc
+++ b/src/nix/ls.cc
@@ -63,7 +63,7 @@ struct MixLs : virtual Args, MixJSON
auto st = accessor->stat(path);
if (st.type == FSAccessor::Type::tMissing)
- throw Error(format("path '%1%' does not exist") % path);
+ throw Error("path '%1%' does not exist", path);
doPath(st, path,
st.type == FSAccessor::Type::tDirectory ? "." : std::string(baseNameOf(path)),
showDirectory);
diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc
index 3e7ff544d..719ea4fd1 100644
--- a/src/nix/make-content-addressable.cc
+++ b/src/nix/make-content-addressable.cc
@@ -85,7 +85,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
if (!json)
- printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
+ printInfo("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
auto source = sinkToSource([&](Sink & nextSink) {
RewritingSink rsink2(oldHashPart, storePathToHash(store->printStorePath(info.path)), nextSink);
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index ea8ff1553..4bcaaeebf 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -218,12 +218,12 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
// input without clearing the input so far.
continue;
} else {
- printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
+ printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg());
}
} catch (Error & e) {
- printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
+ printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg());
} catch (Interrupted & e) {
- printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
+ printMsg(lvlError, error + "%1%%2%", (settings.showTrace ? e.prefix() : ""), e.msg());
}
// We handled the current input fully, so we should clear it
@@ -512,7 +512,7 @@ bool NixRepl::processLine(string line)
return false;
else if (command != "")
- throw Error(format("unknown command '%1%'") % command);
+ throw Error("unknown command '%1%'", command);
else {
size_t p = line.find('=');
diff --git a/src/nix/run.cc b/src/nix/run.cc
index b888281a5..c9b69aec7 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -197,10 +197,10 @@ void chrootHelper(int argc, char * * argv)
Finally freeCwd([&]() { free(cwd); });
if (chroot(tmpDir.c_str()) == -1)
- throw SysError(format("chrooting into '%s'") % tmpDir);
+ throw SysError("chrooting into '%s'", tmpDir);
if (chdir(cwd) == -1)
- throw SysError(format("chdir to '%s' in chroot") % cwd);
+ throw SysError("chdir to '%s' in chroot", cwd);
} else
if (mount(realStoreDir.c_str(), storeDir.c_str(), "", MS_BIND, 0) == -1)
throw SysError("mounting '%s' on '%s'", realStoreDir, storeDir);
diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc
index 678780f33..fdf94e5a3 100644
--- a/src/nix/upgrade-nix.cc
+++ b/src/nix/upgrade-nix.cc
@@ -68,7 +68,11 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
if (dryRun) {
stopProgressBar();
- printError("would upgrade to version %s", version);
+ logWarning(
+ ErrorInfo {
+ .name = "Version update",
+ .hint = hintfmt("would upgrade to version %s", version)
+ });
return;
}
@@ -94,7 +98,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
{"--profile", profileDir, "-i", store->printStorePath(storePath), "--no-sandbox"});
}
- printError(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version);
+ printInfo(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version);
}
/* Return the profile in which Nix is installed. */
diff --git a/src/nix/verify.cc b/src/nix/verify.cc
index 287dad101..246b4b480 100644
--- a/src/nix/verify.cc
+++ b/src/nix/verify.cc
@@ -99,11 +99,15 @@ struct CmdVerify : StorePathsCommand
if (hash.first != info->narHash) {
corrupted++;
act2.result(resCorruptedPath, store->printStorePath(info->path));
- printError(
- "path '%s' was modified! expected hash '%s', got '%s'",
- store->printStorePath(info->path), info->narHash.to_string(Base32, true), hash.first.to_string(Base32, true));
+ logError({
+ .name = "Hash error - path modified",
+ .hint = hintfmt(
+ "path '%s' was modified! expected hash '%s', got '%s'",
+ store->printStorePath(info->path),
+ info->narHash.to_string(Base32, true),
+ hash.first.to_string(Base32, true))
+ });
}
-
}
if (!noTrust) {
@@ -139,7 +143,7 @@ struct CmdVerify : StorePathsCommand
doSigs(info2->sigs);
} catch (InvalidPath &) {
} catch (Error & e) {
- printError(format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what());
+ logError(e.info());
}
}
@@ -150,7 +154,12 @@ struct CmdVerify : StorePathsCommand
if (!good) {
untrusted++;
act2.result(resUntrustedPath, store->printStorePath(info->path));
- printError("path '%s' is untrusted", store->printStorePath(info->path));
+ logError({
+ .name = "Untrusted path",
+ .hint = hintfmt("path '%s' is untrusted",
+ store->printStorePath(info->path))
+ });
+
}
}
@@ -158,7 +167,7 @@ struct CmdVerify : StorePathsCommand
done++;
} catch (Error & e) {
- printError(format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what());
+ logError(e.info());
failed++;
}