Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sentry-panic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![warn(missing_docs)]
#![deny(unsafe_code)]

#[allow(deprecated)] // `PanicHookInfo` is only available in Rust 1.81+.
use std::panic::{self, PanicInfo};
use std::sync::Once;

Expand All @@ -31,6 +32,7 @@ use sentry_core::{ClientOptions, Integration};
/// This panic handler reports panics to Sentry. It also attempts to prevent
/// double faults in some cases where it's known to be unsafe to invoke the
/// Sentry panic handler.
#[allow(deprecated)] // `PanicHookInfo` is only available in Rust 1.81+.
pub fn panic_handler(info: &PanicInfo<'_>) {
sentry_core::with_integration(|integration: &PanicIntegration, hub| {
hub.capture_event(integration.event_from_panic_info(info));
Expand All @@ -40,6 +42,7 @@ pub fn panic_handler(info: &PanicInfo<'_>) {
});
}

#[allow(deprecated)] // `PanicHookInfo` is only available in Rust 1.81+.
type PanicExtractor = dyn Fn(&PanicInfo<'_>) -> Option<Event<'static>> + Send + Sync;

/// The Sentry Panic handler Integration.
Expand Down Expand Up @@ -75,6 +78,7 @@ impl Integration for PanicIntegration {
}

/// Extract the message of a panic.
#[allow(deprecated)] // `PanicHookInfo` is only available in Rust 1.81+.
pub fn message_from_panic_info<'a>(info: &'a PanicInfo<'_>) -> &'a str {
match info.payload().downcast_ref::<&'static str>() {
Some(s) => s,
Expand All @@ -93,6 +97,7 @@ impl PanicIntegration {

/// Registers a new extractor.
#[must_use]
#[allow(deprecated)] // `PanicHookInfo` is only available in Rust 1.81+.
pub fn add_extractor<F>(mut self, f: F) -> Self
where
F: Fn(&PanicInfo<'_>) -> Option<Event<'static>> + Send + Sync + 'static,
Expand All @@ -104,6 +109,7 @@ impl PanicIntegration {
/// Creates an event from the given panic info.
///
/// The stacktrace is calculated from the current frame.
#[allow(deprecated)] // `PanicHookInfo` is only available in Rust 1.81+.
pub fn event_from_panic_info(&self, info: &PanicInfo<'_>) -> Event<'static> {
for extractor in &self.extractors {
if let Some(event) = extractor(info) {
Expand Down