Skip to main content

setup_panic

Macro setup_panic 

Source
macro_rules! setup_panic {
    ($submit_error_report:ty, $check_if_known_error:ident) => { ... };
}
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 $check_if_known_error)
  • 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

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

§Arguments

  • $submit_error_report — A type implementing SubmitErrorReport (e.g. GitLabErrorReport)
  • $check_if_known_error — A function fn(&str) -> Option<String> that returns a message if the panic matches a known issue, or None to generate a report

§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() {
    setup_panic!(GitLabErrorReport, check_if_common_errors);
}