From d16a66a2f53a83d65a84ea8f8de4f817aff5efee Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sun, 21 Jun 2026 13:48:41 -0400 Subject: [PATCH] Use match instead of map_err for Contextualize on Result --- src/util/error.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)), + } } }