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
Use error
instead of *Error
in Group
#58
base: main
Are you sure you want to change the base?
Conversation
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.
f5409ce
to
7d7a61a
Compare
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 |
@@ -6,7 +6,7 @@ import "sync" | |||
// coalesced. | |||
type Group struct { | |||
mutex sync.Mutex | |||
err *Error | |||
err error |
There was a problem hiding this comment.
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()
.
@@ -30,7 +30,7 @@ func (g *Group) Go(f func() error) { | |||
|
|||
// 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 { |
There was a problem hiding this comment.
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.
Changes the type of
Group.err
toerror
instead of*Error
, and also changes the return value ofGroup.Wait
toerror
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