Repository navigation
fix(core): keep the io::Error of error variants as their source - #674
Open
stefanwichmann wants to merge 1 commit into
Open
stefanwichmann wants to merge 1 commit into
stefanwichmann wants to merge 1 commit into
Conversation
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>
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.
Related to #643.
What and why
Ten
LocalDestinationErrorKindvariants (DirectoryCreationFailed,DirectoryRemovalFailed,FileRemovalFailed,SettingTimeMetadataFailed,OpeningFileFailed,SettingFileLengthFailed,CouldNotSeekToPositionInFile,CouldNotWriteToBuffer,ReadingExactLengthOfFileFailed,SettingFilePermissionsFailed) andSnapshotFileErrorKind::RemovingDotsFromPathFailedwrap astd::io::Errorin a tuple field without#[source]. thiserror only treats a field as the source when it is namedsourceor marked, soError::source()returnsNone, and theio::Errorsurvives only in the rendered message, e.g.directory creation failed: `Os { code: 13, kind: PermissionDenied, … }`. A library consumer that wantsraw_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 asource(ListingXattrsFailedand 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_sourcecreates a directory below a regular file and asserts that the error's source downcasts tostd::io::Error. Onmainit fails ("the error has no source").The five integration failures (
backup×2,ls,rewrite,vfs) fail identically onmainon macOS: the unpacked fixtures pick up acom.apple.provenanceextended attribute that the recorded snapshots don't have.🤖 Generated with Claude Code