Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(core): keep the io::Error of error variants as their source - #674

Open
stefanwichmann wants to merge 1 commit into
rustic-rs:mainfrom
stefanwichmann:fix/chain-io-error-sources
Open

stefanwichmann wants to merge 1 commit into
rustic-rs:mainfrom
stefanwichmann:fix/chain-io-error-sources

Conversation

@stefanwichmann

Copy link
Copy Markdown
Contributor

Related to #643.

What and why

Ten LocalDestinationErrorKind variants (DirectoryCreationFailed, DirectoryRemovalFailed, FileRemovalFailed, SettingTimeMetadataFailed, OpeningFileFailed, SettingFileLengthFailed, CouldNotSeekToPositionInFile, CouldNotWriteToBuffer, ReadingExactLengthOfFileFailed, SettingFilePermissionsFailed) and SnapshotFileErrorKind::RemovingDotsFromPathFailed wrap a std::io::Error in a tuple field without #[source]. thiserror only treats a field as the source when it is named source or marked, so Error::source() returns None, and the io::Error survives only in the rendered message, e.g. directory creation failed: `Os { code: 13, kind: PermissionDenied, … }` . A library consumer that wants raw_os_error(), to tell a permission denial from a full disk during a restore, has to parse it out of that text. These are the only such variants in the crate.

This PR marks each field #[source]. The messages keep their {0:?}, like the struct variants that already chain a source (ListingXattrsFailed and others). As a result, RusticError's rendering now shows the cause twice, once in the message and once as (source: …). Happy to drop the {0:?} from the messages if you prefer.

Tests

New unit test backend::local_destination::tests::a_failed_directory_creation_keeps_its_io_error_as_the_source creates a directory below a regular file and asserts that the error's source downcasts to std::io::Error. On main it fails ("the error has no source").

cargo fmt --all -- --check                                   # ok
cargo clippy --all-targets --all-features -- -D warnings     # ok
cargo test -p rustic_core --all-targets --all-features       # lib 206 passed; integration 65 passed, 5 failed

The five integration failures (backup ×2, ls, rewrite, vfs) fail identically on main on macOS: the unpacked fixtures pick up a com.apple.provenance extended attribute that the recorded snapshots don't have.

🤖 Generated with Claude Code

Ten `LocalDestinationErrorKind` variants and
`SnapshotFileErrorKind::RemovingDotsFromPathFailed` wrap a
`std::io::Error` in a tuple field without `#[source]`. thiserror only
treats a field as the source when it is named `source` or marked, so
`Error::source()` returned `None` and the `io::Error` survived only in
the rendered message (`{0:?}`). A library consumer that wants the OS
error number, to tell a permission denial from a full disk, had to
parse it out of that text.

Mark each field `#[source]`. The messages keep their `{0:?}`, as the
struct variants that already chain a `source` do.

New test `a_failed_directory_creation_keeps_its_io_error_as_the_source`
creates a directory below a regular file and asserts that the error's
source downcasts to `std::io::Error`; on main it fails with no source.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant