From 3b1784d346c15720b44a7c79adc7ae56ec8c9c3e Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 28 Nov 2025 18:41:53 +0800 Subject: [PATCH] make screen panic messages somewhat more useful some panic messages are hundreds of characters long, most of them are path hashes or paths to crates that are less useful. truncate any panic messages to the last set of displayable characters, so that the "most useful" portion (e.g. file name and line number) are always visible in a panic. --- services/bao-video/src/panic.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/services/bao-video/src/panic.rs b/services/bao-video/src/panic.rs index 26d098f9e..f4027dee8 100644 --- a/services/bao-video/src/panic.rs +++ b/services/bao-video/src/panic.rs @@ -124,7 +124,17 @@ pub(crate) fn panic_handler_thread( } .get(); let s = unsafe { core::str::from_utf8_unchecked(&body.buf.as_slice()[..len]) }; - append_string(s, &mut display); + const MAX_CHARS: usize = 7 * 18; // 7 lines by 18 characters is what the display can hold + if s.chars().count() <= MAX_CHARS { + append_string(s, &mut display); + } else { + // truncate very long panic messages to just show the *end* as that contains the useful + // information (the front tends to be stuff like path information in the build) + append_string( + s.char_indices().rev().take(MAX_CHARS).last().map(|(i, _)| &s[i..]).unwrap(), + &mut display, + ); + } display.draw(); } }