Skip to content

Conversation

@thaJeztah
Copy link
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)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Sep 8, 2025
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Sep 8, 2025
@codecov-commenter
Copy link

Codecov Report

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

Files with missing lines Patch % Lines
cli/command/container/update.go 0.00% 3 Missing ⚠️
cli/command/node/ps.go 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

var (
warns []string
errs []string
errs []error
Copy link
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.

var errs error
errs = errors.Join(errs, err)
errs = errors.Join(errs, err)

Copy link
Member Author

@thaJeztah thaJeztah Sep 9, 2025

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"
)

func main() {
	errs := []error{
		errors.New("one"),
		errors.New("two"),
		errors.New("three"),
	}
	var nested error
	for _, err := range errs {
		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
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
Member Author

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:master Sep 9, 2025
96 checks passed
@thaJeztah thaJeztah deleted the use_multierror branch September 9, 2025 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants