Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

lib: Pretty-print PanicInfo #5

Merged
merged 2 commits into from
Aug 19, 2022

Conversation

har7an
Copy link
Contributor

@har7an har7an commented Aug 17, 2022

instead of relying solely on the Debug trait for printing. Also add
some more space to the output, so the Panic is easily recognized between
application text and the backtrace.

Currently, accessing the panic message is an unstable feature in core, see this tracking issue: rust-lang/rust#66745

So unless this lands, the current debug print actually contains more useful information than this PR...

instead of relying solely on the `Debug` trait for printing. Also add
some more space to the output, so the Panic is easily recognized between
application text and the backtrace.
@har7an har7an marked this pull request as draft August 17, 2022 13:15
@har7an har7an mentioned this pull request Aug 17, 2022
@har7an har7an force-pushed the feature/pretty-panic-messages branch from 08e0650 to 31a4788 Compare August 19, 2022 12:29
@har7an har7an marked this pull request as ready for review August 19, 2022 12:31
@har7an har7an changed the title WIP: lib: Pretty-print PanicInfo lib: Pretty-print PanicInfo Aug 19, 2022
@har7an
Copy link
Contributor Author

har7an commented Aug 19, 2022

@bjoernQ I learned another trick yesterday, apparently "{:#?}" pretty-prints sturcts in rust, so the output of this PR now looks like this:

======================================
Self-built SX128x example code, no-std
Features:
  - UART


!! A panic occured in 'src/main.rs', at line 77, column 5

PanicInfo {
    payload: Any { .. },
    message: Some(
        Hallo,
    ),
    location: Location {
        file: "src/main.rs",
        line: 77,
        col: 5,
    },
    can_unwind: true,
}

Backtrace:

0x400d495e [sx128x_demo::__xtensa_lx_rt_main:/var/home/ahartmann/repos/mt/playground/sx128x-demo/src/main.rs:77]
0x400d752c [Reset:/usr/local/share/cargo/registry/src/github.com-1ecc6299db9ec823/xtensa-lx-rt-0.13.0/src/lib.rs:77]
0x400d5a41 [ESP32Reset:/usr/local/share/cargo/git/checkouts/esp-hal-33cf057932915da5/d1a2b98/esp32-hal/src/lib.rs:77]

What do you think about it?

@bjoernQ
Copy link
Contributor

bjoernQ commented Aug 19, 2022

@bjoernQ I learned another trick yesterday, apparently "{:#?}" pretty-prints sturcts in rust, so the output of this PR now looks like this:

======================================
Self-built SX128x example code, no-std
Features:
  - UART


!! A panic occured in 'src/main.rs', at line 77, column 5

PanicInfo {
    payload: Any { .. },
    message: Some(
        Hallo,
    ),
    location: Location {
        file: "src/main.rs",
        line: 77,
        col: 5,
    },
    can_unwind: true,
}

Backtrace:

0x400d495e [sx128x_demo::__xtensa_lx_rt_main:/var/home/ahartmann/repos/mt/playground/sx128x-demo/src/main.rs:77]
0x400d752c [Reset:/usr/local/share/cargo/registry/src/github.com-1ecc6299db9ec823/xtensa-lx-rt-0.13.0/src/lib.rs:77]
0x400d5a41 [ESP32Reset:/usr/local/share/cargo/git/checkouts/esp-hal-33cf057932915da5/d1a2b98/esp32-hal/src/lib.rs:77]

What do you think about it?

Good idea!

@bjoernQ
Copy link
Contributor

bjoernQ commented Aug 19, 2022

@jessebraham what do you think?

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is big improvement :)

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, this is much more pleasant to look at 😁 Thanks for the contribution!

@jessebraham jessebraham merged commit a795863 into esp-rs:main Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants