-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
field/error: Handle panic in Error() #867
Conversation
Codecov Report
@@ Coverage Diff @@
## master #867 +/- ##
==========================================
- Coverage 98.36% 98.21% -0.15%
==========================================
Files 43 43
Lines 2390 1910 -480
==========================================
- Hits 2351 1876 -475
+ Misses 32 27 -5
Partials 7 7
Continue to review full report at Codecov.
|
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.
Thank you for the contribution @FMLS
Using reflect
check for nil
isn't always right, as it's possible to have a nil
value that implements the error
interface,
https://play.golang.org/p/5T8S35zdGsH
To handle nil in this case, please follow the same logic used by Stringer
to detect a nil panic (which uses recover
, similar to the standard library).
We shouldn't panic if the `Error()` method of an `error` panics. ``` type T struct{ msg string } func (t *T) Error() string { return t.msg } // The following panics. var n *T = nil log.Info("panic", zap.Error(n)) ``` Co-authored-by: Abhinav Gupta <mail@abhinavg.net>
We shouldn't panic if the
Error()
method of anerror
panics.