1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-14 13:01:05 +01:00

Merge pull request #13862 from obsidiansystems/build-failure-content-vs-presentation

Properly separater builder failure content and presentation
This commit is contained in:
Jörg Thalheim 2025-09-01 20:25:50 +02:00 committed by GitHub
commit 0d300112fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 48 additions and 34 deletions

View file

@ -633,11 +633,6 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
{
goal.closeLogFile();
}
void appendLogTailErrorMsg(std::string & msg) override
{
goal.appendLogTailErrorMsg(msg);
}
};
auto * localStoreP = dynamic_cast<LocalStore *>(&worker.store);
@ -725,6 +720,9 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
SingleDrvOutputs builtOutputs;
try {
builtOutputs = builder->unprepareBuild();
} catch (BuilderFailureError & e) {
outputLocks.unlock();
co_return doneFailure(fixupBuilderFailureErrorMessage(std::move(e)));
} catch (BuildError & e) {
outputLocks.unlock();
// Allow selecting a subset of enum values
@ -835,8 +833,16 @@ static void runPostBuildHook(
});
}
void DerivationBuildingGoal::appendLogTailErrorMsg(std::string & msg)
BuildError DerivationBuildingGoal::fixupBuilderFailureErrorMessage(BuilderFailureError e)
{
auto msg =
fmt("Cannot build '%s'.\n"
"Reason: " ANSI_RED "builder %s" ANSI_NORMAL ".",
Magenta(worker.store.printStorePath(drvPath)),
statusToString(e.builderStatus));
msg += showKnownOutputs(worker.store, *drv);
if (!logger->isVerbose() && !logTail.empty()) {
msg += fmt("\nLast %d log lines:\n", logTail.size());
for (auto & line : logTail) {
@ -853,6 +859,10 @@ void DerivationBuildingGoal::appendLogTailErrorMsg(std::string & msg)
nixLogCommand,
worker.store.printStorePath(drvPath));
}
msg += e.extraMsgAfter;
return BuildError{e.status, msg};
}
Goal::Co DerivationBuildingGoal::hookDone()
@ -893,21 +903,13 @@ Goal::Co DerivationBuildingGoal::hookDone()
/* Check the exit status. */
if (!statusOk(status)) {
auto msg =
fmt("Cannot build '%s'.\n"
"Reason: " ANSI_RED "builder %s" ANSI_NORMAL ".",
Magenta(worker.store.printStorePath(drvPath)),
statusToString(status));
msg += showKnownOutputs(worker.store, *drv);
appendLogTailErrorMsg(msg);
auto e = fixupBuilderFailureErrorMessage({BuildResult::MiscFailure, status, ""});
outputLocks.unlock();
/* TODO (once again) support fine-grained error codes, see issue #12641. */
co_return doneFailure(BuildError{BuildResult::MiscFailure, msg});
co_return doneFailure(std::move(e));
}
/* Compute the FS closure of the outputs and register them as