Skip to content

build-result: Make Failure an alias for BuildError#15070

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
amaanq:build-result-error-cleanup
Jan 29, 2026
Merged

build-result: Make Failure an alias for BuildError#15070
Ericson2314 merged 1 commit intoNixOS:masterfrom
amaanq:build-result-error-cleanup

Conversation

@amaanq
Copy link
Member

@amaanq amaanq commented Jan 23, 2026

Motivation

This PR makes BuildResult::Failure a type alias for BuildError, so failures can be thrown directly without maintaining a separate exception field.

Context

Previously, the goal system tracked failures in two places:

  • BuildResult::Failure struct in buildResult.inner
  • std::optional<Error> ex field on Goal

I've set an alias BuildResult::Failure = BuildError (note that BuildError inherits from Error). This lets us remove the exception parameters from doneFailure(), and also lets us remove the Goal::ex field. Now, we use buildResult.tryGetFailure() to get a throwable exception directly.

The ecNoSubstituters exit code is handled specially in that it sets a Failure in buildResult but isn't logged as an error, since it effectively means "we couldn't substitute, will try building instead."


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store labels Jan 23, 2026
@Ericson2314 Ericson2314 marked this pull request as draft January 23, 2026 21:39
@amaanq amaanq force-pushed the build-result-error-cleanup branch from a739985 to 1d7c4e9 Compare January 23, 2026 23:10
@github-actions github-actions bot added the c api Nix as a C library with a stable interface label Jan 23, 2026
@amaanq amaanq changed the title Create proper serializer for BuildResult status build-result: Make Failure an alias for BuildError Jan 23, 2026
@amaanq amaanq changed the title build-result: Make Failure an alias for BuildError build-result: Make Failure an alias for BuildError Jan 23, 2026
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice cleanup, also the decoupling from the worker protocol.

Comment on lines +153 to +157
for (auto && [wire, val] : enumerate(buildResultStatusTable))
if (val == status) {
conn.to << uint8_t(wire);
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wasteful but is probably ok.
Something more direct would be nice, but I assume this isn't in the hot path, so let's not sweat it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the first commit btw. I assume the compiler will be excited to optimize this, hehe. :)

@amaanq amaanq force-pushed the build-result-error-cleanup branch 3 times, most recently from 3520180 to 19d03c9 Compare January 26, 2026 17:04
@amaanq amaanq requested a review from roberth January 26, 2026 17:08
@amaanq amaanq force-pushed the build-result-error-cleanup branch from 19d03c9 to c94ab82 Compare January 26, 2026 18:11
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jan 26, 2026
@amaanq amaanq force-pushed the build-result-error-cleanup branch from c94ab82 to 9f5a6d7 Compare January 26, 2026 19:09
@dpulls
Copy link

dpulls bot commented Jan 26, 2026

🎉 All dependencies have been resolved !

@amaanq amaanq marked this pull request as ready for review January 26, 2026 22:06
@amaanq amaanq force-pushed the build-result-error-cleanup branch from 9f5a6d7 to ebe702d Compare January 26, 2026 22:07
@Ericson2314 Ericson2314 added this pull request to the merge queue Jan 28, 2026
@Ericson2314 Ericson2314 removed this pull request from the merge queue due to a manual request Jan 28, 2026

Goal::Done PathSubstitutionGoal::doneFailure(ExitCode result, BuildResult::Failure::Status status, std::string errorMsg)
{
debug(errorMsg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new codepath doesn't issue this debug, do we care?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We got rid of this function because it was a redundant wrapper around Goal::doneFailure, I believe the debug log isn't something we care about but John can gut check me on that.

@amaanq amaanq force-pushed the build-result-error-cleanup branch from ebe702d to de88141 Compare January 29, 2026 00:33
@Ericson2314 Ericson2314 added this pull request to the merge queue Jan 29, 2026
Merged via the queue into NixOS:master with commit 1713f4c Jan 29, 2026
14 checks passed
@amaanq amaanq deleted the build-result-error-cleanup branch January 29, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants