Skip to content

Commit

Permalink
Merge pull request #279 from dtolnay/contextbacktrace
Browse files Browse the repository at this point in the history
Remove 2 frames of noise from 'context' backtraces
  • Loading branch information
dtolnay committed Oct 20, 2022
2 parents f2123ab + 131249b commit 54fc812
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/context.rs
Expand Up @@ -47,15 +47,23 @@ where
where
C: Display + Send + Sync + 'static,
{
self.map_err(|error| error.ext_context(context))
// Not using map_err to save 2 useless frames off the captured backtrace
// in ext_context.
match self {
Ok(ok) => Ok(ok),
Err(error) => Err(error.ext_context(context)),
}
}

fn with_context<C, F>(self, context: F) -> Result<T, Error>
where
C: Display + Send + Sync + 'static,
F: FnOnce() -> C,
{
self.map_err(|error| error.ext_context(context()))
match self {
Ok(ok) => Ok(ok),
Err(error) => Err(error.ext_context(context())),
}
}
}

Expand Down

0 comments on commit 54fc812

Please sign in to comment.