Skip to content

feat(backend): Add error sources #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl LocalSource {
for line in std::fs::read_to_string(file)
.map_err(|err| IgnoreErrorKind::ErrorGlob {
file: file.into(),
err,
source: err,
})?
.lines()
{
Expand All @@ -190,7 +190,7 @@ impl LocalSource {
for line in std::fs::read_to_string(file)
.map_err(|err| IgnoreErrorKind::ErrorGlob {
file: file.into(),
err,
source: err,
})?
.lines()
{
Expand Down Expand Up @@ -260,8 +260,13 @@ impl ReadSourceOpen for OpenFile {
/// [`IgnoreErrorKind::UnableToOpenFile`]: crate::error::IgnoreErrorKind::UnableToOpenFile
fn open(self) -> RusticResult<Self::Reader> {
let path = self.0;
File::open(&path)
.map_err(|err| IgnoreErrorKind::UnableToOpenFile { file: path, err }.into())
File::open(&path).map_err(|err| {
IgnoreErrorKind::UnableToOpenFile {
file: path,
source: err,
}
.into()
})
}
}

Expand Down Expand Up @@ -410,7 +415,7 @@ fn map_entry(
let path = entry.path();
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
path: path.to_path_buf(),
err,
source: err,
})?;
let node_type = NodeType::from_link(&target);
Node::new_node(name, node_type, meta)
Expand Down Expand Up @@ -535,15 +540,15 @@ fn map_entry(
xattr::list(path)
.map_err(|err| IgnoreErrorKind::ErrorXattr {
path: path.to_path_buf(),
err,
source: err,
})?
.map(|name| {
Ok(ExtendedAttribute {
name: name.to_string_lossy().to_string(),
value: xattr::get(path, name)
.map_err(|err| IgnoreErrorKind::ErrorXattr {
path: path.to_path_buf(),
err,
source: err,
})?
.unwrap(),
})
Expand Down Expand Up @@ -574,7 +579,7 @@ fn map_entry(
let path = entry.path();
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
path: path.to_path_buf(),
err,
source: err,
})?;
let node_type = NodeType::from_link(&target);
Node::new_node(name, node_type, meta)
Expand Down
9 changes: 6 additions & 3 deletions crates/core/src/backend/local_destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,12 @@ impl LocalDestination {
let filename = self.path(item);
let mut done = vec![false; extended_attributes.len()];

for curr_name in xattr::list(&filename)
.map_err(|err| LocalDestinationErrorKind::ListingXattrsFailed(err, filename.clone()))?
{
for curr_name in xattr::list(&filename).map_err(|err| {
LocalDestinationErrorKind::ListingXattrsFailed {
source: err,
path: filename.clone(),
}
})? {
match extended_attributes.iter().enumerate().find(
|(_, ExtendedAttribute { name, .. })| name == curr_name.to_string_lossy().as_ref(),
) {
Expand Down
40 changes: 30 additions & 10 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,30 @@ pub enum CryptBackendErrorKind {
pub enum IgnoreErrorKind {
/// generic Ignore error: `{0:?}`
GenericError(#[from] ignore::Error),
/// Error reading glob file {file:?}: {err:?}
ErrorGlob { file: PathBuf, err: std::io::Error },
/// Unable to open file {file:?}: {err:?}
UnableToOpenFile { file: PathBuf, err: std::io::Error },
/// Error getting xattrs for {path:?}: {err:?}
ErrorXattr { path: PathBuf, err: std::io::Error },
/// Error reading link target for {path:?}: {err:?}
ErrorLink { path: PathBuf, err: std::io::Error },
/// Error reading glob file {file:?}: {source:?}
ErrorGlob {
file: PathBuf,
#[source]
source: std::io::Error,
},
/// Unable to open file {file:?}: {source:?}
UnableToOpenFile {
file: PathBuf,
#[source]
source: std::io::Error,
},
/// Error getting xattrs for {path:?}: {source:?}
ErrorXattr {
path: PathBuf,
#[source]
source: std::io::Error,
},
/// Error reading link target for {path:?}: {source:?}
ErrorLink {
path: PathBuf,
#[source]
source: std::io::Error,
},
/// `{0:?}`
#[error(transparent)]
FromTryFromIntError(#[from] TryFromIntError),
Expand All @@ -613,9 +629,13 @@ pub enum LocalDestinationErrorKind {
#[error(transparent)]
#[cfg(not(windows))]
FromErrnoError(#[from] Errno),
/// listing xattrs on {1:?}: {0}
/// listing xattrs on {path:?}: {source:?}
#[cfg(not(any(windows, target_os = "openbsd")))]
ListingXattrsFailed(std::io::Error, PathBuf),
ListingXattrsFailed {
path: PathBuf,
#[source]
source: std::io::Error,
},
/// setting xattr {name} on {filename:?} with {source:?}
#[cfg(not(any(windows, target_os = "openbsd")))]
SettingXattrFailed {
Expand Down