Skip to main content

setup_panic

Macro setup_panic 

Source
macro_rules! setup_panic {
    () => { ... };
}
Expand description

Set up a custom panic hook with issue submission and known-error matching.

Replaces the default panic handler with one that:

  • Checks if the panic matches a known error (via ERGlobalSettings::check_known_error_types_fn)
  • In release builds: shows a user-friendly message with a report link
  • In debug builds: shows the full error report with a clickable issue URL

How the Error is displayed is handled by an SubmitErrorReport You need to specify which reporter you want to use via ERGlobalSettings::submit_error_reporter_fn.

Only active when RUST_BACKTRACE is not set (falls back to default otherwise).

ยงExample

use charon_error::prelude::*;
use charon_error::prelude::gitlab_er::*;

fn check_if_common_errors(msg: &str) -> Option<String> {
    if msg.contains("out of memory") {
        Some("Try closing other applications".to_owned())
    } else {
        None
    }
}

fn main() {
    ERGlobalSettings::set_global_settings(ERGlobalSettings {
        check_known_error_types_fn: check_if_common_errors,
        submit_error_reporter_fn: |er| Box::new(GitLabErrorReport::new(er)),
        ..Default::default()
    }).unwrap();
    setup_panic!();
}