Skip to content

use native errors.Join for multi-errors on "docker ps", "docker node ls" - #6440

Merged
thaJeztah merged 2 commits into
docker:masterfrom
thaJeztah:use_multierror
Sep 9, 2025
Merged

use native errors.Join for multi-errors on "docker ps", "docker node ls"#6440
thaJeztah merged 2 commits into
docker:masterfrom
thaJeztah:use_multierror

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztahthaJeztah added this to the 29.0.0 milestone Sep 8, 2025
@thaJeztahthaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Sep 8, 2025
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing linesPatch %Lines
cli/command/container/update.go0.00%3 Missing ⚠️
cli/command/node/ps.go83.33%1 Missing ⚠️

📢 Thoughts on this report? Let us know!

var (
warns []string
errs []string
errs []error

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it is possible to use errors.Join directly on the error type instead of a slice.

varerrserrorerrs=errors.Join(errs, err)
errs=errors.Join(errs, err)

@thaJeztahthaJeztahSep 9, 2025

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, they're subtly different though; repeatedly calling errors.Join effectively is similar to errors.Wrap; the new error is nesting previous errors, whereas a slice approach makes them all "peers"; https://go.dev/play/p/42cXzTSkjoA

package main
import (
"errors""fmt"
)
funcmain() {
errs:= []error{
errors.New("one"),
errors.New("two"),
errors.New("three"),
}
varnestederrorfor_, err:=rangeerrs {
nested=errors.Join(nested, err)
}
flat:=errors.Join(errs...)
fmt.Printf("Flat : %#v\n", flat)
fmt.Printf("Nested: %#v\n", nested)
}

Output;

Flat : &errors.joinError{errs:[]error{(*errors.errorString)(0xc000012040), (*errors.errorString)(0xc000012050), (*errors.errorString)(0xc000012060)}}
Nested: &errors.joinError{errs:[]error{(*errors.joinError)(0xc00000e060), (*errors.errorString)(0xc000012060)}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

interesting, i thought it might've behaved the same

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, I think they chose a bad name for the function; I was confused as well when I was pointed at it! Join feels like "same level", not "wrap errors to be nested".

In many cases it doesn't make a big difference, e.g. errors.Is will recurse, so will still find nested errors (which sometimes is a bit of a pain / unwanted as well), but sometimes it may matter ("peer" errors vs "nested errors")

@thaJeztah
thaJeztah merged commit 62d2520 into docker:masterSep 9, 2025
96 checks passed
@thaJeztah
thaJeztah deleted the use_multierror branch September 9, 2025 08:47
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactorPR's that refactor, or clean-up codestatus/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@thaJeztah@codecov-commenter@Benehiko