-
-
Notifications
You must be signed in to change notification settings - Fork 205
Closed
Description
I just switched from Snafu to thiserror, and on the whole my code has become a lot cleaner and clearer.
One thing that I miss is Snafu’s context() method on Result. It works much like the context() method in anyhow, but it allows adding structured context to an error. My current use case:
#[derive(Debug, Error)]
enum MyError {
// . . .
#[error("failed reading page {path:?}")]
ReadPageFile { source: io::Error, path: PathBuf },
}
impl MyError {
#[allow(non_snake_case)]
fn ReadPageFileMap(path: &Path) -> Box<dyn FnOnce(io::Error) -> MyError> {
let path = PathBuf::from(path);
Box::new(|source: io::Error| MyError::ReadPageFile { source, path })
}
}
fn read_from(path: &Path) -> Result<Page> {
let raw = fs::read_to_string(path)
.map_err(MyError::ReadPageFileMap(path))?;
// . . .
}Put more simply, I just want a convenient way to convert an io::Error into MyError::ReadPageFile while adding a path field to it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels