diff --git a/src/util/error.rs b/src/util/error.rs index ae9a4bf..1366520 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -229,7 +229,12 @@ pub trait Contextualize { impl> Contextualize> for Result { #[track_caller] fn err_context(self, context: impl Into) -> Result { - 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)), + } } }