Use match instead of map_err for Contextualize on Result
This commit is contained in:
@@ -229,7 +229,12 @@ pub trait Contextualize<R> {
|
||||
impl<T, E: Into<Error>> Contextualize<Result<T, Error>> for Result<T, E> {
|
||||
#[track_caller]
|
||||
fn err_context(self, context: impl Into<String>) -> Result<T, Error> {
|
||||
self.map_err(|e| e.into().with_context(context))
|
||||
// Closures can't (currently) `track_caller`, so a simple map_err doesn't work
|
||||
// See https://github.com/rust-lang/rust/issues/87417
|
||||
match self {
|
||||
Ok(e) => Ok(e),
|
||||
Err(e) => Err(e.into().with_context(context)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user