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

Add a helper for formatting multiple errors #2365

Merged
merged 4 commits into from
Apr 5, 2024
Merged

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Apr 3, 2024

As of Go 1.20, the standard library supposedly contains infrastructure for reporting multiple errors.

Sadly, that infrastructure is mostly unhelpful: errors.Join gives no control over formatting, and fmt.Errorf does not support a []error input. So, introduce our own multierr.Format, and use it where possible.

Then remove the go-multierror dependency. The net result is not particularly better code, but at least we try to work with the standard library design.

(This was originally motivated just by trying to remove the go-multierror dependency in #2364, now that the standard library supposedly supports the feature.)

This might, in some cases, change whether the returned error matches errors.{As,Is}, mostly because the previous code for aggregating multiple errors was written before Go 1.20 made it possible for multiple errors to match. (Not that I know how the multi-matching design can ever be all that useful…)

See individual commit messages for details.

It's sad that this is even necessary, but using fmt.Errorf with an []error
is way too inconvenient without a helper.

Only adds a new function, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This may make errors visible to errors.As/errors.Is

This commit, in general, attempts not to change the formatting;
only in newShortNameAliasCache, the order of the errors is no longer
reversed.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Don't treat the first error specially.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@rhatdan
Copy link
Member

rhatdan commented Apr 4, 2024

LGTM
@giuseppe PTAL

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

/lgtm

@rhatdan rhatdan merged commit 9af3fbd into containers:main Apr 5, 2024
10 checks passed
@mtrmac mtrmac deleted the multierr branch April 5, 2024 14:08
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