Skip to content

Use error instead of *Error in Group#58

Open
ccampo133 wants to merge 1 commit intohashicorp:mainfrom
ccampo133:return_error_from_wait
Open

Use error instead of *Error in Group#58
ccampo133 wants to merge 1 commit intohashicorp:mainfrom
ccampo133:return_error_from_wait

Conversation

@ccampo133
Copy link

@ccampo133 ccampo133 commented Nov 12, 2021

Changes the type of Group.err to error instead of *Error, and also changes the return value of Group.Wait to error instead of *Error. The *Error concrete type can lead to unintuitive, subtle bugs around nil checks (see: https://golang.org/doc/faq#nil_error). Returning the error interface instead eliminates this possibility. Note that because this changes a public API signature, it should be considered a breaking change.

Fixes #57

@hashicorp-cla
Copy link

hashicorp-cla commented Nov 12, 2021

CLA assistant check
All committers have signed the CLA.

Changes the return value of Group.Wait to error instead of *Error. The *Error concrete type can lead to unintuitive, subtle bugs around nil checks (see: https://golang.org/doc/faq#nil_error). Returning the error interface instead eliminates these. Addresses hashicorp#57.
@ccampo133 ccampo133 force-pushed the return_error_from_wait branch from f5409ce to 7d7a61a Compare November 12, 2021 21:01
@dolmen
Copy link

dolmen commented Mar 24, 2024

That would be a breaking change, so unlikely to be accepted.

The only solution at this point would be a linter detecting a call to Group.Wait being assigned to an error variable.

type Group struct {
mutex sync.Mutex
err *Error
err error
Copy link

@dolmen dolmen Mar 24, 2024

Choose a reason for hiding this comment

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

This change is not necessary.

Instead Wait should return g.err.ErrorOrNil().

Copy link

Choose a reason for hiding this comment

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

agree

Copy link
Author

Choose a reason for hiding this comment

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

This is a matter of opinion. You could also say using *Error here is unnecessary. Using error is consistent with the API as written in this PR.

// Wait blocks until all function calls from the Go method have returned, then
// returns the multierror.
func (g *Group) Wait() *Error {
func (g *Group) Wait() error {
Copy link

Choose a reason for hiding this comment

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

This breaks the existing API.

Copy link
Author

@ccampo133 ccampo133 May 22, 2024

Choose a reason for hiding this comment

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

Yes. Unfortunately it is a poorly designed API. Release a v2.

@ccampo133
Copy link
Author

That would be a breaking change, so unlikely to be accepted.

The only solution at this point would be a linter detecting a call to Group.Wait being assigned to an error variable.

In the current version of the API, you are correct. There could certainly be a v2 release though.

Unfortunately this is a poorly designed API for the reasons I point out in #57. In fact, I stopped using it years ago, shortly after I ran into this issue. I don't believe there much need for this library now since https://pkg.go.dev/golang.org/x/sync/errgroup exists along with Go 1.20's error joining.

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.

error nil check weirdness with Group.Wait

4 participants