|
| 1 | +use core::fmt::{self, Debug, Display}; |
| 2 | +use std::panic::RefUnwindSafe; |
| 3 | + |
| 4 | +#[derive(Debug)] |
| 5 | +#[allow(dead_code)] |
| 6 | +pub struct PanicError { |
| 7 | + pub(crate) message: String, |
| 8 | + pub(crate) location: Option<String>, |
| 9 | + pub(crate) backtrace: Option<Backtrace>, |
| 10 | + pub(crate) thread_name: String, |
| 11 | +} |
| 12 | + |
| 13 | +impl Display for PanicError { |
| 14 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 15 | + writeln!(f, "PANIC")?; |
| 16 | + Ok(()) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +impl std::error::Error for PanicError {} |
| 21 | + |
| 22 | +impl PanicError { |
| 23 | + pub(crate) fn new(message: String) -> Self { |
| 24 | + Self { |
| 25 | + message, |
| 26 | + location: None, |
| 27 | + backtrace: None, |
| 28 | + thread_name: thread_name(), |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +pub fn catch<F: RefUnwindSafe + FnOnce() -> Output, Output>(fun: F) -> Result<Output, PanicError> { |
| 34 | + Ok(fun()) |
| 35 | +} |
| 36 | + |
| 37 | +pub fn take_panic() -> Option<PanicError> { |
| 38 | + None |
| 39 | +} |
| 40 | + |
| 41 | +pub fn capture_backtrace(_value: bool) -> bool { |
| 42 | + false |
| 43 | +} |
| 44 | + |
| 45 | +pub fn forward_panic(_value: bool) -> bool { |
| 46 | + false |
| 47 | +} |
| 48 | + |
| 49 | +pub fn set_hook() { |
| 50 | + // no-op |
| 51 | +} |
| 52 | + |
| 53 | +pub fn rust_backtrace() -> bool { |
| 54 | + false |
| 55 | +} |
| 56 | + |
| 57 | +pub fn thread_name() -> String { |
| 58 | + String::from("main") |
| 59 | +} |
| 60 | + |
| 61 | +#[derive(Debug)] |
| 62 | +pub struct Backtrace(()); |
| 63 | + |
| 64 | +impl Display for Backtrace { |
| 65 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 66 | + writeln!(f, "backtrace")?; |
| 67 | + Ok(()) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +#[derive(Debug)] |
| 72 | +pub struct BacktraceFrame(()); |
0 commit comments