tezos_smart_rollup_panic_hook/
lib.rs1#![deny(missing_docs)]
8#![deny(rustdoc::broken_intra_doc_links)]
9
10#![no_std]
17
18#[cfg(feature = "std")]
20extern crate std;
21
22extern crate alloc;
23
24use core::panic::PanicInfo;
25
26#[allow(unused)]
30pub fn panic_handler(info: &PanicInfo) {
31 #[cfg(feature = "debug")]
32 {
33 let message = if let Some(message) =
34 info.payload().downcast_ref::<alloc::string::String>()
35 {
36 alloc::format!("Kernel panic {:?} at {:?}", message, info.location())
37 } else {
38 let message = info.payload().downcast_ref::<&str>();
39 alloc::format!("Kernel panic {:?} at {:?}", message, info.location())
40 };
41
42 #[cfg(any(target_arch = "wasm32", target_arch = "riscv64"))]
43 unsafe {
44 tezos_smart_rollup_core::smart_rollup_core::write_debug(
45 message.as_ptr(),
46 message.len(),
47 );
48 }
49
50 #[cfg(all(feature = "std", not(target_arch = "wasm32")))]
51 std::eprintln!("{}", message);
52 }
53
54 #[cfg(all(feature = "abort", target_arch = "wasm32"))]
56 std::process::abort()
57}