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

Replace usage of utils.Err with errors.Join #3167

Merged
merged 4 commits into from
Jul 2, 2024
Merged

Conversation

joshua-kim
Copy link
Contributor

Why this should be merged

Remove helper we maintain and use the stdlib instead

How this works

Removes utils.Err

How this was tested

CI

@joshua-kim joshua-kim self-assigned this Jul 2, 2024
Signed-off-by: Joshua Kim <[email protected]>
@joshua-kim joshua-kim added the cleanup Code quality improvement label Jul 2, 2024
@joshua-kim joshua-kim marked this pull request as ready for review July 2, 2024 19:07
Signed-off-by: Joshua Kim <[email protected]>
func Err(errors ...error) error {
for _, err := range errors {
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

A subtle change between errors.Join and utils.Err is that utils.Err returns the first error whereas errors.Join returns a combined error (https://go.dev/play/p/n4_zaEd4ODl):

import (
	"errors"
	"fmt"
)

func main() {
	err1 := errors.New("err1")
	err2 := errors.New("err2")
	err := errors.Join(err1, err2)
	fmt.Println(err)
	if errors.Is(err, err1) {
		fmt.Println("err is err1")
	}
	if errors.Is(err, err2) {
		fmt.Println("err is err2")
	}
}
err1
err2
err is err1
err is err2

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this matters for our use-cases but thought I'd point it out

@StephenButtolph StephenButtolph added this pull request to the merge queue Jul 2, 2024
@StephenButtolph StephenButtolph added this to the v1.11.9 milestone Jul 2, 2024
Merged via the queue into master with commit e20115c Jul 2, 2024
20 checks passed
@StephenButtolph StephenButtolph deleted the errors-join branch July 2, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants