field/error: Handle panic in Error()#867
Merged
Merged
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.
|
prashantv
requested changes
Oct 6, 2020
Collaborator
prashantv
left a comment
There was a problem hiding this comment.
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).
abhinav
reviewed
Nov 24, 2020
abhinav
reviewed
Nov 24, 2020
abhinav
approved these changes
Nov 24, 2020
prashantv
approved these changes
Nov 24, 2020
RenovZ
pushed a commit
to RenovZ/zap
that referenced
this pull request
Mar 25, 2022
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>
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.
We shouldn't panic if the
Error()method of anerrorpanics.