Skip to content

Commit

Permalink
fix(errors): Show filenames in error message coming from ignore source (
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome authored May 1, 2024
1 parent f3ad6e9 commit 32a5737
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
35 changes: 28 additions & 7 deletions crates/core/src/backend/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ impl LocalSource {

for file in &filter_opts.glob_file {
for line in std::fs::read_to_string(file)
.map_err(IgnoreErrorKind::FromIoError)?
.map_err(|err| IgnoreErrorKind::ErrorGlob {
file: file.into(),
err,
})?
.lines()
{
_ = override_builder
Expand All @@ -185,7 +188,10 @@ impl LocalSource {

for file in &filter_opts.iglob_file {
for line in std::fs::read_to_string(file)
.map_err(IgnoreErrorKind::FromIoError)?
.map_err(|err| IgnoreErrorKind::ErrorGlob {
file: file.into(),
err,
})?
.lines()
{
_ = override_builder
Expand Down Expand Up @@ -254,7 +260,8 @@ 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(err).into())
File::open(&path)
.map_err(|err| IgnoreErrorKind::UnableToOpenFile { file: path, err }.into())
}
}

Expand Down Expand Up @@ -400,7 +407,11 @@ fn map_entry(
let node = if m.is_dir() {
Node::new_node(name, NodeType::Dir, meta)
} else if m.is_symlink() {
let target = read_link(entry.path()).map_err(IgnoreErrorKind::FromIoError)?;
let path = entry.path();
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
path: path.to_path_buf(),
err,
})?;
let node_type = NodeType::from_link(&target);
Node::new_node(name, node_type, meta)
} else {
Expand Down Expand Up @@ -522,12 +533,18 @@ fn map_entry(
let extended_attributes = {
let path = entry.path();
xattr::list(path)
.map_err(IgnoreErrorKind::FromIoError)?
.map_err(|err| IgnoreErrorKind::ErrorXattr {
path: path.to_path_buf(),
err,
})?
.map(|name| {
Ok(ExtendedAttribute {
name: name.to_string_lossy().to_string(),
value: xattr::get(path, name)
.map_err(IgnoreErrorKind::FromIoError)?
.map_err(|err| IgnoreErrorKind::ErrorXattr {
path: path.to_path_buf(),
err,
})?
.unwrap(),
})
})
Expand All @@ -554,7 +571,11 @@ fn map_entry(
let node = if m.is_dir() {
Node::new_node(name, NodeType::Dir, meta)
} else if m.is_symlink() {
let target = read_link(entry.path()).map_err(IgnoreErrorKind::FromIoError)?;
let path = entry.path();
let target = read_link(path).map_err(|err| IgnoreErrorKind::ErrorLink {
path: path.to_path_buf(),
err,
})?;
let node_type = NodeType::from_link(&target);
Node::new_node(name, node_type, meta)
} else if filetype.is_block_device() {
Expand Down
15 changes: 8 additions & 7 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,17 @@ pub enum CryptBackendErrorKind {
pub enum IgnoreErrorKind {
/// generic Ignore error: `{0:?}`
GenericError(#[from] ignore::Error),
/// Unable to open file: {0:?}
UnableToOpenFile(std::io::Error),
/// `{0:?}`
#[error(transparent)]
FromIoError(#[from] std::io::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 },
/// `{0:?}`
#[error(transparent)]
FromTryFromIntError(#[from] TryFromIntError),
/// no unicode link target. File: {file:?}, target: {target:?}
TargetIsNotValidUnicode { file: PathBuf, target: PathBuf },
}

/// [`LocalDestinationErrorKind`] describes the errors that can be returned by an action on the filesystem in Backends
Expand Down

0 comments on commit 32a5737

Please sign in to comment.