Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

[errors] Make MultiError mutable #135

Open
prateek opened this issue Mar 31, 2018 · 0 comments
Open

[errors] Make MultiError mutable #135

prateek opened this issue Mar 31, 2018 · 0 comments

Comments

@prateek
Copy link
Contributor

prateek commented Mar 31, 2018

In an effort to keep errors.MultiErr immutable, we have the following for the Add method:

// Add adds an error returns a new MultiError object.
func (e MultiError) Add(err error) MultiError {
	if err == nil {
		return e
	}
	me := e
	if me.err == nil {
		me.err = err
		return me
	}
	me.errors = append(me.errors, me.err)
	me.err = err
	return me
}

There's a couple of issues with this:

  • Almost every time someone unfamiliar with the API uses it, they mess up.
  • We never need to keep the original value around, so we always use this like: mulitErr = multiErr.Add(...)

We should just change the signature to make it apparent the method mutates the underlying struct: func (e *MultiError) Add(err error) { ... }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant