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 multierr.Every #78

Merged
merged 3 commits into from Mar 28, 2023
Merged

Support multierr.Every #78

merged 3 commits into from Mar 28, 2023

Conversation

JacobOaks
Copy link
Contributor

@JacobOaks JacobOaks commented Mar 28, 2023

This PR introduces a new exported function in the multierr package called Every, which checks every error within a given error against a given target using errors.Is, and only returns true if all checks return true.

err := multierr.Combine(ErrIgnorable, errors.New("great sadness"))
fmt.Println(errors.Is(err, ErrIgnorable))      // output = "true"
fmt.Println(multierr.Every(err, ErrIgnorable)) // output = "false"

err := multierr.Combine(ErrIgnorable, ErrIgnorable)
fmt.Println(errors.Is(err, ErrIgnorable))      // output = "true"
fmt.Println(multierr.Every(err, ErrIgnorable)) // output = "true"

This also works when the error passed in as the first argument is not a multiErr, including when it is a go1.20+ error that implements Unwrap() []error.

This solves #66.

This PR introduces a new exported function in the multierr package
called `Every`, which checks every error within a given error
against a given target using `errors.Is`, and only returns true if
all checks return true.

```go
err := multierr.Combine(ErrIgnorable, errors.New("great sadness"))
fmt.Println(multierr.Every(err, ErrIgnorable))
// output = "false"

err := multierr.Combine(ErrIgnorable, ErrIgnorable)
fmt.Println(multierr.Every(err, ErrIgnorable)
// output = "true"
```

This also works when the error passed in as the first argument is not a `multiErr`,
including when it is a go1.20+ error that implements `Unwrap() []error`.

This solves uber-go#66.
wantEvery: false,
},
{
desc: "multiErr w multiErr target",
Copy link

Choose a reason for hiding this comment

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

nice.

error_test.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #78 (7b893ed) into master (d42b7a1) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master       #78   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          117       120    +3     
=========================================
+ Hits           117       120    +3     
Impacted Files Coverage Δ
error.go 100.00% <100.00%> (ø)

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

@JacobOaks JacobOaks merged commit d8067ab into uber-go:master Mar 28, 2023
5 checks passed
@JacobOaks JacobOaks deleted the every branch March 28, 2023 20:51
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.

None yet

3 participants