Use match instead of map_err for Contextualize on Result

This commit is contained in:
2026-06-21 13:48:41 -04:00
parent 1cf1bfcfbc
commit d16a66a2f5

View File

@@ -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)),
}
}
}