Skip to content
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

zapcore: Improve errors unit tests #1414

Merged
merged 2 commits into from Mar 7, 2024

Conversation

justinhwang
Copy link
Contributor

@justinhwang justinhwang commented Feb 7, 2024

Updates and adds some unit tests for the zapcore/errors.go file.

Previously, implementing `ObjectMarshaler` on an error type was ignored
unless the error was logged with `zap.Any` or `zap.Object`. We should
respect the `ObjectMarshaler` instead as this is more flexible than the
basic `error` or `fmt.Formatter` interfaces.

Resolves uber-go#1365
zapcore/error.go Outdated
// In the case of a ObjectMarshaler,
//
// {
// "error": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is a breaking change as we would have an object here instead of a string but I would argue that this would be the intended behavior when someone implements ObjectMarshaler on their error type.

@sywhang
Copy link
Contributor

sywhang commented Mar 1, 2024

See #641 for a previous discussion on this.

tl;dr is that this change is a bigger breaking change than we want. Ideally we want to make this happen without breaking existing users of Zap.

@justinhwang justinhwang changed the title zapcore: Support ObjectMarshaler for error types zapcore: Improve errors unit tests Mar 4, 2024
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.69%. Comparing base (e5745d6) to head (c3d3011).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1414      +/-   ##
==========================================
+ Coverage   98.44%   98.69%   +0.25%     
==========================================
  Files          53       53              
  Lines        3527     2997     -530     
==========================================
- Hits         3472     2958     -514     
+ Misses         46       31      -15     
+ Partials        9        8       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tchung1118 tchung1118 merged commit b39f8b6 into uber-go:master Mar 7, 2024
8 checks passed
@justinhwang justinhwang deleted the justinhwang/errobj branch March 11, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants