From a0a6a13014ad6aaf62095b42cdf8cc4cac09f54f Mon Sep 17 00:00:00 2001 From: Hankai Zhang Date: Sat, 10 Jun 2023 18:38:35 -0400 Subject: [PATCH] Print informative panic message in release build --- kernel/src/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 1b08786..282e4c7 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -217,7 +217,23 @@ fn panic(panic_info: &PanicInfo) -> ! { if let Some(mut locked_term) = TERMINAL.as_inner().try_lock() { // The terminal may not yet be initialized. if let Some(ref mut term) = &mut *locked_term { - let _ = core::fmt::write(term, format_args!("\x1B[1;31m{}\x1B[m", panic_info)); + if !cfg!(debug_assertions) { + // Clear the screen + term.print("\x1B[H\x1B[2J"); + } + term.print("\x1B[1;31m"); + if !cfg!(debug_assertions) { + term.print( + "KERNEL PANIC\n\n\ + A severe error has occurred in the Doors operating system and it has been shut \ + down. If this is a reproducible or recurring issue, you may want to file a bug \ + report at https://github.com/SamZhang3/doors-rs, with the below information and \ + possibly other details regarding what actions trigger the problem.\n\n\ + Technical details:", + ); + } + let _ = core::fmt::write(term, format_args!("\n{}", panic_info)); + term.print("\x1B[m"); } }