flipperzero_rt/
panic_handler.rs1use core::panic::PanicInfo;
5
6use flipperzero_sys as sys;
7
8#[panic_handler]
9pub fn panic(panic_info: &PanicInfo<'_>) -> ! {
10 unsafe {
13 let thread_id = sys::furi_thread_get_current_id();
14 let thread_name = if !thread_id.is_null() {
15 sys::furi_thread_get_name(thread_id)
16 } else {
17 c"unknown".as_ptr()
18 };
19
20 sys::__wrap_printf(c"\x1b[0;31mthread: '%s' paniced".as_ptr(), thread_name);
21
22 if let Some(s) = panic_info.message().as_str() {
23 sys::__wrap_printf(c" at '%.*s'".as_ptr(), s.len(), s.as_ptr());
24 }
25
26 if let Some(location) = panic_info.location() {
27 let file = location.file();
28 let line = location.line();
29
30 sys::__wrap_printf(c", %.*s:%u".as_ptr(), file.len(), file.as_ptr(), line);
31 }
32
33 sys::__wrap_printf(c"\x1b[0m\r\n".as_ptr());
34 sys::furi_thread_stdout_flush();
35
36 sys::furi_delay_ms(500);
38
39 sys::crash!("Rust panic")
40 }
41}