Skip to content

Commit 06af9cb

Browse files
committed
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 :).
1 parent a39ed67 commit 06af9cb

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

src/libstore/build/derivation-goal.cc

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -922,51 +922,16 @@ Goal::Co DerivationGoal::hookDone()
922922
/* Close the log file. */
923923
closeLogFile();
924924

925-
try {
926-
927-
/* Check the exit status. */
928-
if (!statusOk(status)) {
929-
auto msg = fmt("builder for '%s' %s",
930-
Magenta(worker.store.printStorePath(drvPath)),
931-
statusToString(status));
932-
933-
appendLogTailErrorMsg(worker, drvPath, logTail, msg);
934-
935-
throw BuildError(msg);
936-
}
937-
938-
/* Compute the FS closure of the outputs and register them as
939-
being valid. */
940-
auto builtOutputs =
941-
/* When using a build hook, the build hook can register the output
942-
as valid (by doing `nix-store --import'). If so we don't have
943-
to do anything here.
944-
945-
We can only early return when the outputs are known a priori. For
946-
floating content-addressing derivations this isn't the case.
947-
*/
948-
assertPathValidity();
949-
950-
StorePathSet outputPaths;
951-
for (auto & [_, output] : builtOutputs)
952-
outputPaths.insert(output.outPath);
953-
runPostBuildHook(
954-
worker.store,
955-
*logger,
956-
drvPath,
957-
outputPaths
958-
);
925+
/* Check the exit status. */
926+
if (!statusOk(status)) {
927+
auto msg = fmt("builder for '%s' %s",
928+
Magenta(worker.store.printStorePath(drvPath)),
929+
statusToString(status));
959930

960-
/* It is now safe to delete the lock files, since all future
961-
lockers will see that the output paths are valid; they will
962-
not create new lock files with the same names as the old
963-
(unlinked) lock files. */
964-
outputLocks.setDeletion(true);
965-
outputLocks.unlock();
931+
appendLogTailErrorMsg(worker, drvPath, logTail, msg);
966932

967-
co_return done(BuildResult::Built, std::move(builtOutputs));
933+
auto e = BuildError(msg);
968934

969-
} catch (BuildError & e) {
970935
outputLocks.unlock();
971936

972937
BuildResult::Status st = BuildResult::MiscFailure;
@@ -988,6 +953,37 @@ Goal::Co DerivationGoal::hookDone()
988953

989954
co_return done(st, {}, std::move(e));
990955
}
956+
957+
/* Compute the FS closure of the outputs and register them as
958+
being valid. */
959+
auto builtOutputs =
960+
/* When using a build hook, the build hook can register the output
961+
as valid (by doing `nix-store --import'). If so we don't have
962+
to do anything here.
963+
964+
We can only early return when the outputs are known a priori. For
965+
floating content-addressing derivations this isn't the case.
966+
*/
967+
assertPathValidity();
968+
969+
StorePathSet outputPaths;
970+
for (auto & [_, output] : builtOutputs)
971+
outputPaths.insert(output.outPath);
972+
runPostBuildHook(
973+
worker.store,
974+
*logger,
975+
drvPath,
976+
outputPaths
977+
);
978+
979+
/* It is now safe to delete the lock files, since all future
980+
lockers will see that the output paths are valid; they will
981+
not create new lock files with the same names as the old
982+
(unlinked) lock files. */
983+
outputLocks.setDeletion(true);
984+
outputLocks.unlock();
985+
986+
co_return done(BuildResult::Built, std::move(builtOutputs));
991987
}
992988

993989
Goal::Co DerivationGoal::resolvedFinished()

0 commit comments

Comments
 (0)