Skip to content

Commit

Permalink
Prettier panic message printing (#1823)
Browse files Browse the repository at this point in the history
* Prettier panic message printing

* CHANGELOG.md
  • Loading branch information
bjoernQ authored Jul 18, 2024
1 parent 776f34c commit 917756a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 44 deletions.
6 changes: 6 additions & 0 deletions esp-backtrace/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Improve panic message printing (#1823)

### Fixed

### Removed

## 0.13.0 - 2024-07-16

No changes - published to avoid conflicts with `esp-println`

## 0.12.2 - 2024-07-15

### Changed
Expand Down
50 changes: 6 additions & 44 deletions esp-backtrace/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#![allow(rustdoc::bare_urls, unused_macros)]
#![cfg_attr(
target_arch = "xtensa",
feature(asm_experimental_arch),
feature(panic_info_message)
)]
#![cfg_attr(target_arch = "xtensa", feature(asm_experimental_arch))]
#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")]
#![no_std]
Expand Down Expand Up @@ -58,47 +54,13 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
set_color_code(RED);

println!("");
println!("");

if let Some(location) = info.location() {
let (file, line, column) = (location.file(), location.line(), location.column());
println!(
"!! A panic occured in '{}', at line {}, column {}:",
file, line, column
);
} else {
println!("!! A panic occured at an unknown location:");
}

#[cfg(not(any(nightly_before_2024_06_12, nightly_since_2024_06_12)))]
{
#[cfg(not(feature = "defmt"))]
println!("{:#?}", info);

#[cfg(feature = "defmt")]
println!("{:#?}", defmt::Display2Format(info));
}
println!("====================== PANIC ======================");

#[cfg(nightly_before_2024_06_12)]
{
if let Some(message) = info.message() {
#[cfg(not(feature = "defmt"))]
println!("{}", message);

#[cfg(feature = "defmt")]
println!("{}", defmt::Display2Format(message));
}
}

#[cfg(nightly_since_2024_06_12)]
{
let message = info.message();
#[cfg(not(feature = "defmt"))]
println!("{}", message);
#[cfg(not(feature = "defmt"))]
println!("{}", info);

#[cfg(feature = "defmt")]
println!("{}", defmt::Display2Format(&message));
}
#[cfg(feature = "defmt")]
println!("{}", defmt::Display2Format(info));

println!("");
println!("Backtrace:");
Expand Down

0 comments on commit 917756a

Please sign in to comment.