mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Improve build failure error messages
They're now laid out in a more readable way, and they shows the output paths (if known).
This commit is contained in:
parent
cdbe788c1f
commit
5a84237209
4 changed files with 54 additions and 8 deletions
|
@ -354,6 +354,22 @@ struct value_comparison
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
std::string showKnownOutputs(Store & store, const Derivation & drv)
|
||||||
|
{
|
||||||
|
std::string msg;
|
||||||
|
StorePathSet expectedOutputPaths;
|
||||||
|
for (auto & i : drv.outputsAndOptPaths(store))
|
||||||
|
if (i.second.second)
|
||||||
|
expectedOutputPaths.insert(*i.second.second);
|
||||||
|
if (!expectedOutputPaths.empty()) {
|
||||||
|
msg += "\nOutput paths:";
|
||||||
|
for (auto & p : expectedOutputPaths)
|
||||||
|
msg += fmt("\n %s", Magenta(store.printStorePath(p)));
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* At least one of the output paths could not be
|
/* At least one of the output paths could not be
|
||||||
produced using a substitute. So we have to build instead. */
|
produced using a substitute. So we have to build instead. */
|
||||||
Goal::Co DerivationGoal::gaveUpOnSubstitution()
|
Goal::Co DerivationGoal::gaveUpOnSubstitution()
|
||||||
|
@ -430,9 +446,14 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
|
||||||
if (nrFailed != 0) {
|
if (nrFailed != 0) {
|
||||||
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));
|
||||||
co_return done(BuildResult::DependencyFailed, {}, Error(
|
auto msg = fmt(
|
||||||
"%s dependencies of derivation '%s' failed to build",
|
"Cannot build '%s'.\n"
|
||||||
nrFailed, worker.store.printStorePath(drvPath)));
|
"Reason: " ANSI_RED "%d %s failed" ANSI_NORMAL ".",
|
||||||
|
Magenta(worker.store.printStorePath(drvPath)),
|
||||||
|
nrFailed,
|
||||||
|
nrFailed == 1 ? "dependency" : "dependencies");
|
||||||
|
msg += showKnownOutputs(worker.store, *drv);
|
||||||
|
co_return done(BuildResult::DependencyFailed, {}, Error(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retrySubstitution == RetrySubstitution::YesNeed) {
|
if (retrySubstitution == RetrySubstitution::YesNeed) {
|
||||||
|
@ -1033,7 +1054,7 @@ void runPostBuildHook(
|
||||||
void DerivationGoal::appendLogTailErrorMsg(std::string & msg)
|
void DerivationGoal::appendLogTailErrorMsg(std::string & msg)
|
||||||
{
|
{
|
||||||
if (!logger->isVerbose() && !logTail.empty()) {
|
if (!logger->isVerbose() && !logTail.empty()) {
|
||||||
msg += fmt(";\nlast %d log lines:\n", logTail.size());
|
msg += fmt("\nLast %d log lines:\n", logTail.size());
|
||||||
for (auto & line : logTail) {
|
for (auto & line : logTail) {
|
||||||
msg += "> ";
|
msg += "> ";
|
||||||
msg += line;
|
msg += line;
|
||||||
|
@ -1090,10 +1111,14 @@ Goal::Co DerivationGoal::hookDone()
|
||||||
|
|
||||||
/* Check the exit status. */
|
/* Check the exit status. */
|
||||||
if (!statusOk(status)) {
|
if (!statusOk(status)) {
|
||||||
auto msg = fmt("builder for '%s' %s",
|
auto msg = fmt(
|
||||||
|
"Cannot build '%s'.\n"
|
||||||
|
"Reason: " ANSI_RED "builder %s" ANSI_NORMAL ".",
|
||||||
Magenta(worker.store.printStorePath(drvPath)),
|
Magenta(worker.store.printStorePath(drvPath)),
|
||||||
statusToString(status));
|
statusToString(status));
|
||||||
|
|
||||||
|
msg += showKnownOutputs(worker.store, *drv);
|
||||||
|
|
||||||
appendLogTailErrorMsg(msg);
|
appendLogTailErrorMsg(msg);
|
||||||
|
|
||||||
outputLocks.unlock();
|
outputLocks.unlock();
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class Store;
|
class Store;
|
||||||
|
struct Derivation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unless we are repairing, we don't both to test validity and just assume it,
|
* Unless we are repairing, we don't both to test validity and just assume it,
|
||||||
|
@ -49,4 +50,9 @@ struct InitialOutput
|
||||||
|
|
||||||
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
|
void runPostBuildHook(Store & store, Logger & logger, const StorePath & drvPath, const StorePathSet & outputPaths);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format the known outputs of a derivation for use in error messages.
|
||||||
|
*/
|
||||||
|
std::string showKnownOutputs(Store & store, const Derivation & drv);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -585,10 +585,14 @@ std::variant<std::pair<BuildResult::Status, Error>, SingleDrvOutputs> Derivation
|
||||||
|
|
||||||
diskFull |= cleanupDecideWhetherDiskFull();
|
diskFull |= cleanupDecideWhetherDiskFull();
|
||||||
|
|
||||||
auto msg = fmt("builder for '%s' %s",
|
auto msg = fmt(
|
||||||
|
"Cannot build '%s'.\n"
|
||||||
|
"Reason: " ANSI_RED "builder %s" ANSI_NORMAL ".",
|
||||||
Magenta(store.printStorePath(drvPath)),
|
Magenta(store.printStorePath(drvPath)),
|
||||||
statusToString(status));
|
statusToString(status));
|
||||||
|
|
||||||
|
msg += showKnownOutputs(store, drv);
|
||||||
|
|
||||||
miscMethods->appendLogTailErrorMsg(msg);
|
miscMethods->appendLogTailErrorMsg(msg);
|
||||||
|
|
||||||
if (diskFull)
|
if (diskFull)
|
||||||
|
|
|
@ -179,12 +179,23 @@ test "$(<<<"$out" grep -cE '^error:')" = 4
|
||||||
out="$(nix build -f fod-failing.nix -L x4 2>&1)" && status=0 || status=$?
|
out="$(nix build -f fod-failing.nix -L x4 2>&1)" && status=0 || status=$?
|
||||||
test "$status" = 1
|
test "$status" = 1
|
||||||
test "$(<<<"$out" grep -cE '^error:')" = 2
|
test "$(<<<"$out" grep -cE '^error:')" = 2
|
||||||
<<<"$out" grepQuiet -E "error: 1 dependencies of derivation '.*-x4\\.drv' failed to build"
|
|
||||||
|
if isDaemonNewer "2.29pre"; then
|
||||||
|
<<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'"
|
||||||
|
<<<"$out" grepQuiet -E "Reason: 1 dependency failed."
|
||||||
|
else
|
||||||
|
<<<"$out" grepQuiet -E "error: 1 dependencies of derivation '.*-x4\\.drv' failed to build"
|
||||||
|
fi
|
||||||
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x2\\.drv'"
|
<<<"$out" grepQuiet -E "hash mismatch in fixed-output derivation '.*-x2\\.drv'"
|
||||||
|
|
||||||
out="$(nix build -f fod-failing.nix -L x4 --keep-going 2>&1)" && status=0 || status=$?
|
out="$(nix build -f fod-failing.nix -L x4 --keep-going 2>&1)" && status=0 || status=$?
|
||||||
test "$status" = 1
|
test "$status" = 1
|
||||||
test "$(<<<"$out" grep -cE '^error:')" = 3
|
test "$(<<<"$out" grep -cE '^error:')" = 3
|
||||||
<<<"$out" grepQuiet -E "error: 2 dependencies of derivation '.*-x4\\.drv' failed to build"
|
if isDaemonNewer "2.29pre"; then
|
||||||
|
<<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'"
|
||||||
|
<<<"$out" grepQuiet -E "Reason: 2 dependencies failed."
|
||||||
|
else
|
||||||
|
<<<"$out" grepQuiet -E "error: 2 dependencies of derivation '.*-x4\\.drv' failed to build"
|
||||||
|
fi
|
||||||
<<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x3\\.drv'"
|
<<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x3\\.drv'"
|
||||||
<<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x2\\.drv'"
|
<<<"$out" grepQuiet -vE "hash mismatch in fixed-output derivation '.*-x2\\.drv'"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue