Filesystem error improvements#15283
Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom Feb 18, 2026
Merged
Conversation
Contributor
|
Probably somewhat fully addresses #11376? Now that we have more wrapper functions for std::filesystem things... |
xokdvium
reviewed
Feb 18, 2026
xokdvium
reviewed
Feb 18, 2026
xokdvium
reviewed
Feb 18, 2026
3891764 to
a53cfcc
Compare
- Make `descriptorToPath` cross-platform (renamed from `windows::handleToPath`). Uses `/proc/self/fd` on Linux and `F_GETPATH` on macOS. Add `HAVE_F_GETPATH` meson check. This is based on 7226a11, which was removed in 479c356, but is now introduced more judiciously. - Unix error messages in `readFull`, `writeFull`, `readLine` now include file paths via `descriptorToPath`. - Convert `std::filesystem::filesystem_error` to `SystemError` Wrappers like `readLink`, `createDirs`, `DirectoryIterator`, etc. now catch `std::filesystem::filesystem_error` and rethrow as `SystemError` with the error code preserved. This ensures consistent exception types throughout the codebase. Call sites that previously caught `filesystem_error` and rethrew with `throw;` now throw `SystemError(e.code(), ...)` instead. Some call sites can stop catching `filesystem_error` at all, because they only call the wrapped functions. - Rework `SystemError` constructors to auto-append error message The public `SystemError(std::error_code, ...)` constructor now automatically appends `errorCode.message()` to the error message. A protected constructor takes an explicit error message string for subclasses. `SysError` delegates to the protected constructor with `strerror(errNo)`. `WinError` delegates with `renderError(lastError)` (now static). This removes the need to manually append `e.code().message()` at call sites when converting `filesystem_error` to `SystemError`. - Use perfect forwarding (`Args &&...` with `std::forward`) consistently in `BaseError`, `SystemError`, `SysError`, and `WinError` constructors. Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo>
a53cfcc to
bbcf204
Compare
xokdvium
reviewed
Feb 18, 2026
| struct ::stat st; | ||
| /* Possible since https://github.com/torvalds/linux/commit/55815f70147dcfa3ead5738fd56d3574e2e3c1c2 (3.6) */ | ||
| if (::fstat(pathFd.get(), &st) == -1) | ||
| throw SysError("statting '%s' relative to parent directory via O_PATH file descriptor", path.rel()); |
Contributor
There was a problem hiding this comment.
Should this also get updated?
Contributor
There was a problem hiding this comment.
Can be left for later I suppose
xokdvium
reviewed
Feb 18, 2026
Contributor
xokdvium
left a comment
There was a problem hiding this comment.
Seems good to me. The error message improvement is good
xokdvium
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
File system error improvements
Make
descriptorToPathcross-platform (renamed fromwindows::handleToPath). Uses/proc/self/fdon Linux andF_GETPATHon macOS. AddHAVE_F_GETPATHmeson check.This is based on 7226a11, which was removed in 479c356, but is now introduced more judiciously.
Unix error messages in
readFull,writeFull,readLinenow include file paths viadescriptorToPath.Convert
std::filesystem::filesystem_errortoSystemErrorWrappers like
readLink,createDirs,DirectoryIterator, etc. now catchstd::filesystem::filesystem_errorand rethrow asSystemErrorwith the error code preserved. This ensures consistent exception types throughout the codebase.Call sites that previously caught
filesystem_errorand rethrew withthrow;now throwSystemError(e.code(), ...)instead.Some call sites can stop catching
filesystem_errorat all, because they only call the wrapped functions.Rework
SystemErrorconstructors to auto-append error messageThe public
SystemError(std::error_code, ...)constructor now automatically appendserrorCode.message()to the error message. A protected constructor takes an explicit error message string for subclasses.SysErrordelegates to the protected constructor withstrerror(errNo).WinErrordelegates withrenderError(lastError)(now static).This removes the need to manually append
e.code().message()at call sites when convertingfilesystem_errortoSystemError.Use perfect forwarding (
Args &&...withstd::forward) consistently inBaseError,SystemError,SysError, andWinErrorconstructors.Context
Possibly fixes #11376
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.