fix(cli): replace unhelpful panic message with an actionable one#717
Merged
Conversation
The panic handler always printed "Uncaught panic: Any { .. }" regardless
of the actual cause, since Box<dyn Any + Send> printed with {:?} shows
the type wrapper, not the message. Rust's default panic hook already
prints the real message, file and line before catch_unwind runs, so
extracting the payload would just repeat that line. Instead the message
now surfaces information the default hook doesn't: the rumdl version
and a link to file a bug.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While reviewing rumdl's error handling I noticed the panic handler in
main.rsalways printsUncaught panic: Any { .. }regardless of what actually caused the crash. That happens becausecatch_unwindreturns the panic payload asBox<dyn Any + Send>, and printing it with{:?}shows the type wrapper, not the message.I first tried extracting the message with
downcast_ref::<&str>()/downcast_ref::<String>(), the pattern shown in the stdlib docs forPanicHookInfo::payload(). That turned out to be redundant: Rust's default panic hook already prints the real message, file and line beforecatch_unwindgets a chance to run, so the extracted text would just repeat the line already shown above it.Instead I replaced the message with something that adds information the default hook does not provide: the rumdl version and a link to file a bug, since an uncaught panic here is always a bug.
Before:
After (forced a panic locally to verify, reverted before this commit):
Exit code unchanged (2).
No behavior change beyond the message text:
catch_unwind, the exit code and control flow stay the same.I didn't add an automated test for this. The message is a fixed string plus
env!("CARGO_PKG_VERSION"), which fails to compile on its own if that were ever missing, and there's no existing way to trigger a real panic through the CLI to exercise this path (the historical panic reports, #85, #87, #154 and #168, were all UTF-8 char-boundary bugs already fixed in earlier releases). I verified the change by temporarily inserting apanic!()in the closure, confirming the output above, and reverting it before committing.Local checks:
cargo buildcargo fmt --checkcargo clippy --workspace --lib --bins --tests -- -D warnings -D clippy::uninlined_format_args