Skip to content

Commit 7791b4f

Browse files
Improve error message on removal
1 parent 283aa76 commit 7791b4f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/utils.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,22 @@ pub(crate) fn remove_dir_all(path: &Path) -> std::io::Result<()> {
7878

7979
#[derive(Debug)]
8080
struct RemoveError {
81-
kind: std::io::ErrorKind,
81+
underlying: std::io::Error,
8282
path: PathBuf,
8383
}
8484

85-
impl std::error::Error for RemoveError {}
85+
impl std::error::Error for RemoveError {
86+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
87+
Some(&self.underlying)
88+
}
89+
}
8690

8791
impl std::fmt::Display for RemoveError {
8892
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8993
f.write_fmt(format_args!(
9094
"failed to remove '{}' : {:?}",
9195
self.path.display(),
92-
self.kind
96+
self.underlying
9397
))
9498
}
9599
}
@@ -98,7 +102,7 @@ fn improve_remove_error(error: std::io::Error, path: &Path) -> std::io::Error {
98102
std::io::Error::new(
99103
error.kind(),
100104
RemoveError {
101-
kind: error.kind(),
105+
underlying: error,
102106
path: path.to_path_buf(),
103107
},
104108
)
@@ -112,7 +116,7 @@ mod tests {
112116
fn custom_remove_error() {
113117
let path = "test/path".as_ref();
114118

115-
let expected = "failed to remove 'test/path' : PermissionDenied";
119+
let expected = "failed to remove 'test/path' : Kind(PermissionDenied)";
116120
let tested = format!(
117121
"{}",
118122
improve_remove_error(

0 commit comments

Comments
 (0)