-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Change default output of panic! #30402
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
I'm a little hesitant to change the format here, there's a few downsides to changing this format I think:
I think that I would personally prefer to leave the message as-is, but I'm curious what others think. cc @rust-lang/libs |
@alexcrichton Let's start with the underlying concern this PR is trying to address: to make panic messages more helpful by e.g. pointing to details about debugging or backtraces. I think this is quite legitimate: many newcomers to Rust will encounter panics first through In other words, I disagree with:
I think the perspective here is really about developers, especially newbies, though it's worth thinking about the end-user experience as well. However, custom handlers will likely help the end-user story for robust apps. (This also addresses your final point.)
Fair point -- let's see if we can find a way to solve the problem while keeping to just one line.
Indeed. And this isn't something we can easily assess via crater, so we'd need to advertise this widely in some way. Could we shrink this change by just adding a short |
Yes I agree with the thrust here, but I also think there's always a price to pay when adding all these "easy to debug" features. An example of this is how we have backtrace support via What I'm getting at is that features we add to help newbies need to be weighed against their technical debt and maintenance cost. I don't think it's the case that "this is more user friendly" is an automatic "oh sure, let's land it!" For example, even if we were to include some sort of URL in the text that's now a link we need to maintain for a very long time to make sure it always works. Not only that, but that text will be embedded in all future rust executables (which may or may not be desired). My own personal feeling as well is that after you see the link once it's basically always extra text you need to scan over. One possible case study for leaving as-is is the |
I do think the user experience matters here, and the current isn't great. Of @alexcrichton's concerns, the interleaving of panics bothers me most, though with the line number and task number remaining on the same line, at least you can figure out where in the source code the panic was, even if you can't figure out what the message was. Regarding the backtrace suggestion, I'm not sure that 'note: ' is the proper UI here - that's the compiler's UI, and there's no similar precedent in the standard library. I do tend to think that the first time a newbie sees a panic is the best time to inform them about what to do about it, but am sympathetic that this adds a lot of noise - a multithreaded program that panics a bunch is going to be too helpful with all the backtrace suggestions. |
Of course, but (1) discoverability of backtraces is hugely important for the newbie experience, given the likelihood of I agree that a URL has downsides, but perhaps we can instead use something like the diagnostic codes you can pass to the compiler to get more information. I'm just trying to get a very short thing we can add that acts as a pointer to more information. That helps with the multiline concern as well as the noisy output concern. Surely there's a way to do that with ~zero maintenance burden? |
Would it be sufficient to provide the additional information just once, when the main thread of the application panics (i.e. basically here Line 63 in 176ee34
This would avoid troubles with interleaving of concurrent panic messages and allow for multiple lines of in-line explanation, which might avoid the burden of maintaining coherence elsewhere. |
We discussed this in the libs triage yesterday and the conclusions we reached were:
@jooert would you be ok implementing these changes? |
@alexcrichton I tried to implement this as specified and added a test for it. Should I update the examples' outputs in the book as well? |
@@ -38,6 +39,7 @@ enum Handler { | |||
|
|||
static HANDLER_LOCK: StaticRwLock = StaticRwLock::new(); | |||
static mut HANDLER: Handler = Handler::Default; | |||
static mut FIRST_PANIC: AtomicBool = AtomicBool::new(true); |
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 can actually just be a plain old static
rather than a static mut
(and all access will be safe!)
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.
Oh, right! I would have thought that compare_and_swap
takes a mutable reference...
Nah I think that's fine to leave off until later if necessary (but cc @steveklabnik if you have an opinion on it) |
The note will only be shown on the first panic.
Updated. Anything else that could be improved? |
Maybe the one-time message could also mention |
I agree that |
This splits the output of panics into two lines as proposed in #15239 and adds a
note about how to get a backtrace. Because the default panic message consists of
multiple lines now, this changes the test runner's failure output to not indent
the first line anymore.
Fixes #15239 and fixes #11704.