-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
testing: panics duplicate information #71517
Comments
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Change https://go.dev/cl/645915 mentions this issue: |
Change https://go.dev/cl/645916 mentions this issue: |
IIUC, this issue could also be avoided if it was possible to only recover a panic for the specific expected type (Eg, #50424 (comment)). The extra frames in the panic output routinely hurt debugability in these situations. |
Recovering a specific type of panic doesn't help with this case. The testing package deliberately recovers panics of all types so it can perform cleanup before re-raising the panic; there is no specific panic that it's looking for. |
Change https://go.dev/cl/647495 mentions this issue: |
A couple of tests generate different output due to CL 645916 for issue #71517. Fixes #71593 Fixes #71594 Change-Id: Ifaeff4e9de8d881202bd9e6394c9b9cff8959596 Reviewed-on: https://go-review.googlesource.com/c/go/+/647495 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
Consider a test which panics:
The testing package produces this output for this test:
Note that the panic value ("oops") is printed twice, because the testing package recovers the panic, performs cleanup, and then re-panics with the same value:
https://go.googlesource.com/go/+/refs/tags/go1.23.5/src/testing/testing.go#1632
This isn't all that much of a problem when the panic message is short, but it can get confusing if the message is long. If the formatted panic value spans multiple lines, the interior panic is indented inconsistently:
This can get exceedingly verbose if the panic message happens to contain stack information itself. (Perhaps that's an argument against putting stack information in panic messages.)
I'm not sure if this is a general problem with how we print panics which reuse the same value, or a problem with the testing package in particular. Perhaps the testing package should use a short, consistent message when re-panicking, since the original panic value will be printed when the panic terminates the program:
Or perhaps
runtime.printpanics
should detect the case where a panic value has been reused:The text was updated successfully, but these errors were encountered: