Skip to content

Catch SystemError in portable code#15015

Merged
Ericson2314 merged 1 commit intomasterfrom
catch-system-error
Jan 20, 2026
Merged

Catch SystemError in portable code#15015
Ericson2314 merged 1 commit intomasterfrom
catch-system-error

Conversation

@Ericson2314
Copy link
Member

Motivation

This will ensure this catching works on Windows too, not just Unix.

Context


Add 👍 to pull requests you find important.

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

This will ensure this catching works on Windows too, not just Unix.
@Ericson2314 Ericson2314 requested a review from edolstra as a code owner January 18, 2026 23:56
@github-actions github-actions bot added new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store fetching Networking with the outside (non-Nix) world, input locking labels Jan 18, 2026
throw SysError("getting status of '%1%'", srcFile);
} catch (SysError & e) {
if (e.errNo == ENOENT || e.errNo == ENOTDIR) {
} catch (SystemError & e) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this work? Above it's throwing a SysError with an errno, but where does the errno get converted to an std::errc that can be caught here?

Copy link
Contributor

@xokdvium xokdvium Jan 19, 2026

Choose a reason for hiding this comment

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

We now store a std::error_code (system_category) and it's comparable to a std::errc even on windows since fd0bcd9. In unix-like system_category is the same as generic_category, which is just the errno. On windows the comparison goes through the first overload of equivalent virtual function https://en.cppreference.com/w/cpp/error/error_category/equivalent.html, which implements a mapping from windows errors to POSIX ones (std::error_condition is implicitly constructible from std::errc: https://en.cppreference.com/w/cpp/error/error_condition/error_condition.html that uses the generic_category: https://en.cppreference.com/w/cpp/error/errc/make_error_condition.html)

Copy link
Contributor

@xokdvium xokdvium left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@Ericson2314 Ericson2314 added this pull request to the merge queue Jan 20, 2026
Merged via the queue into master with commit a59bc63 Jan 20, 2026
18 checks passed
@Ericson2314 Ericson2314 deleted the catch-system-error branch January 20, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants