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

Support Go 1.20 Unwrap() []error #69

Merged
merged 2 commits into from
Feb 10, 2023
Merged

Support Go 1.20 Unwrap() []error #69

merged 2 commits into from
Feb 10, 2023

Conversation

abhinav
Copy link
Collaborator

@abhinav abhinav commented Feb 10, 2023

Go 1.20 includes native support for wrapping multiple errors.
Errors which wrap multiple other errors must implement,

Unwrap() []error

If an error implements this method, errors.Is and errors.As
will descend into the list and continue matching.

Versions of Go prior to 1.20, however, still need the old
Is and As method implementations on the error object
to get a similar behavior.

This change adds the Unwrap() []error method
gated by a build constraint requiring Go 1.20 or higher.
It similarly moves the existing Is and As methods
to a file that is ignored on Go 1.20 or higher.

Once Go 1.21 is released and 1.19 is no longer supported,
the pre-go1.20 file may be deleted and the build constraints removed.

For details, see also the section,
"How should existing multierror types adopt the new interface?"
of the multiple errors proposal.

Refs #64

Go 1.20 includes native support for wrapping multiple errors.
Errors which wrap multiple other errors must implement,

    Unwrap() []error

If an error implements this method, `errors.Is` and `errors.As`
will descend into the list and continue matching.

Versions of Go prior to 1.20, however, still need the old
`Is` and `As` method implementations on the error object
to get a similar behavior.

This change adds the `Unwrap() []error` method
gated by a build constraint requiring Go 1.20 or higher.
It similarly moves the existing `Is` and `As` methods
to a file that is ignored on Go 1.20 or higher.

Once Go 1.21 is released and 1.19 is no longer supported,
the pre-go1.20 file may be deleted and the build constraints removed.

For details, see also the section,
"How should existing multierror types adopt the new interface?"
of the [multiple errors proposal][1].

  [1]: golang/go#53435
@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Merging #69 (d43186a) into master (39ca40c) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master       #69   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         3    +2     
  Lines          109       110    +1     
=========================================
+ Hits           109       110    +1     
Impacted Files Coverage Δ
error.go 100.00% <ø> (ø)
error_post_go120.go 100.00% <100.00%> (ø)
error_pre_go120.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link

@r-hang r-hang left a 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! lgtm!

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

👍

@sywhang sywhang merged commit 55bc553 into uber-go:master Feb 10, 2023
@abhinav abhinav deleted the go120 branch February 10, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants