Function sentry_core::event_from_error

source ·
pub fn event_from_error<E: Error + ?Sized>(err: &E) -> Event<'static>
Expand description

Create a sentry Event from a std::error::Error.

A chain of errors will be resolved as well, and sorted oldest to newest, as described in the sentry event payloads.

§Examples

use thiserror::Error;

#[derive(Debug, Error)]
#[error("inner")]
struct InnerError;

#[derive(Debug, Error)]
#[error("outer")]
struct OuterError(#[from] InnerError);

let event = sentry::event_from_error(&OuterError(InnerError));
assert_eq!(event.level, sentry::protocol::Level::Error);
assert_eq!(event.exception.len(), 2);
assert_eq!(&event.exception[0].ty, "InnerError");
assert_eq!(event.exception[0].value, Some("inner".into()));
assert_eq!(&event.exception[1].ty, "OuterError");
assert_eq!(event.exception[1].value, Some("outer".into()));