1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 01:51:47 +02:00

Inline the try-catch BuildError in the hook case

In the local building case, there is many things which can through
`BuildError`, but in the hook case there is just this one. We can
therefore simplify the code by "cinching" down the logic just to the
spot the error is thrown.

There is other code outside `libstore/build` which also uses
`BuildError`, but I believe those cases are mistakes. The point of
`BuildError` is the narrow technical use-cases of "errors which should
not be fatal with `--keep-going`". Using it outside the
building/scheduling code doesn't really make sense in that regard. It
seems likely that those usages were instead merely because "oh, this
error has something to do with building, so I guess `BuildError` is
better than `Error`".

It is quite likely that I myself used `BuildError` incorrectly as
described above :).
This commit is contained in:
John Ericson 2025-03-12 16:26:16 -04:00
parent a39ed67180
commit 06af9cb532

View file

@ -922,8 +922,6 @@ Goal::Co DerivationGoal::hookDone()
/* Close the log file. */
closeLogFile();
try {
/* Check the exit status. */
if (!statusOk(status)) {
auto msg = fmt("builder for '%s' %s",
@ -932,7 +930,28 @@ Goal::Co DerivationGoal::hookDone()
appendLogTailErrorMsg(worker, drvPath, logTail, msg);
throw BuildError(msg);
auto e = BuildError(msg);
outputLocks.unlock();
BuildResult::Status st = BuildResult::MiscFailure;
#ifndef _WIN32
if (WIFEXITED(status) && WEXITSTATUS(status) == 101)
st = BuildResult::TimedOut;
else if (WIFEXITED(status) && WEXITSTATUS(status) == 100)
{
assert(derivationType);
st =
dynamic_cast<NotDeterministic*>(&e) ? BuildResult::NotDeterministic :
statusOk(status) ? BuildResult::OutputRejected :
!derivationType->isSandboxed() ? BuildResult::TransientFailure :
BuildResult::PermanentFailure;
}
#endif
co_return done(st, {}, std::move(e));
}
/* Compute the FS closure of the outputs and register them as
@ -965,29 +984,6 @@ Goal::Co DerivationGoal::hookDone()
outputLocks.unlock();
co_return done(BuildResult::Built, std::move(builtOutputs));
} catch (BuildError & e) {
outputLocks.unlock();
BuildResult::Status st = BuildResult::MiscFailure;
#ifndef _WIN32
if (WIFEXITED(status) && WEXITSTATUS(status) == 101)
st = BuildResult::TimedOut;
else if (WIFEXITED(status) && WEXITSTATUS(status) == 100)
{
assert(derivationType);
st =
dynamic_cast<NotDeterministic*>(&e) ? BuildResult::NotDeterministic :
statusOk(status) ? BuildResult::OutputRejected :
!derivationType->isSandboxed() ? BuildResult::TransientFailure :
BuildResult::PermanentFailure;
}
#endif
co_return done(st, {}, std::move(e));
}
}
Goal::Co DerivationGoal::resolvedFinished()