ckb_sentry_anyhow/lib.rs
1//! Adds support for capturing Sentry errors from `anyhow::Error`.
2//!
3//! # Example
4//!
5//! ```no_run
6//! use ckb_sentry_anyhow as sentry_anyhow;
7//!
8//! use sentry_anyhow::capture_anyhow;
9//!
10//! fn function_that_might_fail() -> anyhow::Result<()> {
11//! Err(anyhow::anyhow!("some kind of error"))
12//! }
13//!
14//! if let Err(err) = function_that_might_fail() {
15//! capture_anyhow(&err);
16//! }
17//! ```
18
19#![doc(html_favicon_url = "https://sentry-brand.storage.googleapis.com/favicon.ico")]
20#![doc(html_logo_url = "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png")]
21#![warn(missing_docs)]
22#![deny(unsafe_code)]
23
24use sentry_core::types::Uuid;
25use sentry_core::Hub;
26
27/// Captures an `anyhow::Error`.
28///
29/// See [module level documentation](index.html) for more information.
30pub fn capture_anyhow(e: &anyhow::Error) -> Uuid {
31 Hub::with_active(|hub| hub.capture_anyhow(e))
32}
33
34/// Hub extension methods for working with `anyhow`.
35pub trait AnyhowHubExt {
36 /// Captures an [`anyhow::Error`] on a specific hub.
37 fn capture_anyhow(&self, e: &anyhow::Error) -> Uuid;
38}
39
40impl AnyhowHubExt for Hub {
41 fn capture_anyhow(&self, e: &anyhow::Error) -> Uuid {
42 let e: &dyn std::error::Error = e.as_ref();
43 self.capture_error(e)
44 }
45}