-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
${key}Verbose and ${key}Causes for wrapped errors #941
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #941 +/- ##
==========================================
+ Coverage 98.02% 98.12% +0.10%
==========================================
Files 44 44
Lines 1974 1975 +1
==========================================
+ Hits 1935 1938 +3
+ Misses 30 29 -1
+ Partials 9 8 -1 ☔ View full report in Codecov by Sentry. |
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.
Thanks! Would you mind rebasing on master?
encodeError cannot provide ${key}Verbose and ${key}Causes fields if the error implements fmt.Formatter and/or errorGroup interfaces but is wrapped. This change uses errors.As instead of a type switch to check if the given error and the underlying errors are compatible with the above interfaces, and computes ${key}Verbose and ${key}Causes fields with unwrapped error. This commit also upgrades github.com/pkg/errors to v0.9.1 because v0.8.1 doesn't support Unwrap method.
Thanks for the quick review. I've just rebased and pushed. |
@abhinav Shall I rebase it one more time so that it has a linear history? |
@jkawamoto No, that shouldn't be necessary. We'll squash this into one commit when we merge it. |
Sorry for the delay in reviewing -- while the change itself looks fine, though there is a small behaviour change that I was worried about. We should figure out what are the behaviour changes that this causes, and see if we should be backwards compatible (e.g., log both errorCauses and errorVerbose, though that leads to a lot of duplication). |
" - foo\n" + | ||
" - bar\n" + | ||
"hello", | ||
"errorCauses": []interface{}{ |
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 is a slight behaviour change, what previously used errorVerbose
now uses errorCauses
.
Yes, in some cases, log entries will have |
Agree that for the multierr use-cases, having Currently, we only check the first error to see if it matches underlying := multierr.Combine(errors.New("a failed"), errors.New("b failed"))
wrapped1 := fmt.Errorf("wrap1: %w", underlying)
wrapped2 := fmt.Errorf("wrap2: %w", wrapped1)
wrapped3 := fmt.Errorf("wrap3 :%w", wrapped2)
logger.Error("no wrap", zap.Error(wrapped3)) This will look like:
This is worse with Given that, I'm not sure if this is something we should change by default. Instead, we could allow error encoding to be more flexible (also discussed in uber-go/multierr#23), so then users can choose how they want their errors encoded. |
I think it's a little subjective but in your example, this output "error":"wrap3 :wrap2: wrap1: a failed; b failed",
"errorCauses":[{"error":"a failed"},{"error":"b failed"}] is the desired one for me. I can retrieve the log with a JSON query and process logs with jq, and the additional messages ("wrap3 :wrap2: wrap1") can be found in the The problem with |
encodeError
cannot provide${key}Verbose
and${key}Causes
fieldsif the error implements
fmt.Formatter
and/orerrorGroup
interfacesbut is wrapped.
This change uses
errors.As
instead of a type switch to check ifthe given error and the underlying errors are compatible with the
above interfaces, and computes
${key}Verbose
and${key}Causes
fieldswith unwrapped error.
This commit also upgrades github.com/pkg/errors to v0.9.1 because
v0.8.1 doesn't support
Unwrap
method.