Skip to content

Support Go 1.20 Unwrap() []error#69

Merged
sywhang merged 2 commits into
uber-go:masterfrom
abhinav:go120
Feb 10, 2023
Merged

Support Go 1.20 Unwrap() []error#69
sywhang merged 2 commits into
uber-go:masterfrom
abhinav:go120

Conversation

@abhinav

@abhinav abhinav commented Feb 10, 2023

Copy link
Copy Markdown
Collaborator

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

codecov Bot commented Feb 10, 2023

Copy link
Copy Markdown

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

@r-hang r-hang left a comment

Copy link
Copy Markdown

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!

@sywhang sywhang left a comment

Copy link
Copy Markdown
Contributor

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