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

Less verbose output for multierr #470

Merged
merged 2 commits into from
Jul 7, 2017
Merged

Less verbose output for multierr #470

merged 2 commits into from
Jul 7, 2017

Conversation

akshayjshah
Copy link
Contributor

Following the discussions on #460, uber-go/multierr#6, and
(most recently) uber-go/multierr#23, reduce log verbosity for
multierr. This is fully backward-compatible with the last released
version of zap.

The small changes introduced here do two things:

  1. First, we either report errorCauses or errorVerbose, but not
    both.
  2. Second, we prefer errorCauses to errorVerbose.

I think that this addresses our top-level wants without breaking any
interfaces or removing behavior we've already shipped.

In a future minor, we can add an ErrorEncoder interface that the
JSON encoder and console encoder implement, and make the error field
attempt an upcast into that type. That would let the user supply their
own error encoder (much like they supply their own time and duration
encoders now). Even if we do that, though, I suspect that we'll want to
preserve the behavior here as the default.

Following the discussions on #460, uber-go/multierr#6, and
(most recently) uber-go/multierr#23, reduce log verbosity for
`multierr`. This is fully backward-compatible with the last released
version of zap.

The small changes introduced here do two things:

1. First, we either report `errorCauses` or `errorVerbose`, but not
   both.
2. Second, we prefer `errorCauses` to `errorVerbose`.

I think that this addresses our top-level wants without breaking any
interfaces or removing behavior we've already shipped.

If we ever decide to cut a new major release of zap, we should treat
errors like durations and times - they're special types for which users
choose a formatter.

In a future release, we can add an `ErrorEncoder` interface that the
JSON encoder and console encoder implement, and make the error field
attempt an upcast into that type. That would let the user supply their
own error encoder (much like they supply their own time and duration
encoders now). Even if we do that, though, I suspect that we'll want to
preserve the behavior here as the default.
@codecov
Copy link

codecov bot commented Jul 6, 2017

Codecov Report

Merging #470 into master will decrease coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #470      +/-   ##
==========================================
- Coverage   97.32%   97.21%   -0.12%     
==========================================
  Files          36       36              
  Lines        1907     1902       -5     
==========================================
- Hits         1856     1849       -7     
- Misses         42       44       +2     
  Partials        9        9
Impacted Files Coverage Δ
zapcore/error.go 93.75% <100%> (-6.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06ca39d...fa33d3b. Read the comment docs.

zapcore/error.go Outdated
if group, ok := err.(errorGroup); ok {
return enc.AddArray(key+"Causes", errArray(group.Errors()))
}

if fancy, ok := err.(fmt.Formatter); ok {
verbose := fmt.Sprintf("%+v", fancy)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: use type switch now that it's one or the other?

switch e := err.(type) {
case errorGroup:
  ...
case fmt.Formatter:
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh...yeah, that totally makes sense.

Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

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

I think this is a step in the right direction, so we should definitely do this.

I'm still thinking about customizability:
uber-go/multierr#23 (comment)

I'd imagine the default error encoder has the same behaviour as this PR.

@akshayjshah
Copy link
Contributor Author

Yep, outlined a plan for making this configurable in the PR description. I'm not planning to put cycles into that until we need that customizability or someone else files an issue, though.

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.

3 participants