-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust: handle panics to show meaningful error #1336
Conversation
c912152
to
2f60114
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern with empty_loop tag and print/busyloop is repeated many times. It would be good to put this into a function like Abort() and just call that.
print_debug!() should probably be renamed if it is not used for debugging but for production messages.
7b5e826
to
cbf9051
Compare
Updated! PTAL 🙏 |
/// displays the input error message on the screen and enters | ||
/// an infinite loop. | ||
#[allow(clippy::empty_loop)] | ||
pub fn abort(err: &str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here -> !
would fit as a return type? Right @NickeZ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if you make it return !
, you can probably remove the clippy lint exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but clippy still complaints
src/rust/bitbox02/src/ui/ui.rs
Outdated
pub fn with_lock_animation<F: Fn()>(f: F) { | ||
pub fn lock_animation_start() { | ||
unsafe { bitbox02_sys::lock_animation_start() }; | ||
f(); | ||
} | ||
|
||
pub fn lock_animation_stop() { | ||
unsafe { bitbox02_sys::lock_animation_stop() }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but if you wanted to keep the with_lock_animation()
wrapper, you could have the callback function return the error and do
unsafe { bitbox02::ui::lock_animation_start(); }
let result = f();
unsafe { bitbox02::ui::lock_animation_stop(); }
result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it in the beginning, but it wasn't working well as I was handling the error inside f(), and the error message was overlapped by the unlock animation. Now it should work properly 👍
cbf9051
to
1908efd
Compare
In b09c333 we added the `panic_immediate_abort` to the rust cargo flags. This caused all the panics previously handled by the handler defined in lib.rs to just show the `hard fault` error message on the screen of the bitbox. This adds the manual handling of some of those panics, to provide useful debug messages.
1908efd
to
7265e60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
In b09c333 we added the
panic_immediate_abort
to the rust cargo flags. This caused all the panics previously handled by the handler defined in lib.rs to just show thehard fault
error message on the screen of the bitbox.This adds the manual handling of some of those panics, to provide useful debug messages.