Skip to content
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

Replace the multierror dependency with a simple error aggregator. #207

Merged
merged 1 commit into from
Dec 17, 2020

Conversation

mattmoor
Copy link
Contributor

@mattmoor mattmoor commented Dec 17, 2020

This lets functions that want to aggregate and return a collection of errors use a []error to accumulate them, and errorutil.Aggregate(list) to turn them into a single error. If the list is empty, the error will be nil. If the list is a singleton, it will return the single error. Otherwise, it will construct a new error combining the constituent error messages.

Fixes: #205

}
}
tf.files = nil
return nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pretty sure this was a bug 😅

limitations under the License.
*/

package estargz
Copy link
Member

Choose a reason for hiding this comment

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

I feel this should be a new subpackage like estargz/errorutil.

@ktock WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's separate this to another package.
@mattmoor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

estargz/errors.go Outdated Show resolved Hide resolved
estargz/build.go Outdated
}
}
tf.files = nil
return nil
return allErr
Copy link
Member

Choose a reason for hiding this comment

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

We should return nil when no error is appended to allErr?

https://play.golang.org/p/cxUefp-NH9a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if nothing is ever appended to it, it is still nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 or you are saying this is the weird Go typed nil nonsense. blah, let me see...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reworked this ~completely to just use []error directly and have the errorutil package expose an Aggregate method for combining them. I think this ends up being a lot simpler, and it avoid the typed nil case.

return strings.Join(points, "\n\t")
}

var _ error = (*Errors)(nil)
Copy link
Member

Choose a reason for hiding this comment

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

We have tests, so we do not need this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reworked the change pretty dramatically, so I'm no longer implementing a custom error type at all anyways.

@AkihiroSuda
Copy link
Member

Please squash commits

This lets functions that want to aggregate and return a collection of errors use a `[]error` to accumulate them, and `errorutil.Aggregate(list)` to turn them into a single `error`.  If the list is empty, the `error` will be nil.  If the list is a singleton, it will return the single error.  Otherwise, it will construct a new error combining the constituent error messages.

Fixes: containerd#205
Signed-off-by: Matt Moore <mattmoor@vmware.com>
@mattmoor
Copy link
Contributor Author

Please squash commits

Given the overhaul I just gave this, I didn't even bother with a squash, since it's a completely different change. I'll update the PR subject and description above now to reflect the new commit message.

@mattmoor mattmoor changed the title Create a simple Errors struct to replace multierror Replace the multierror dependency with a simple error aggregator. Dec 17, 2020
Copy link
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

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

LGTM on green.

@mattmoor
Copy link
Contributor Author

Thanks for the quick review, and thanks again for driving this super important work! 🤩

@ktock ktock merged commit e2f7fff into containerd:master Dec 17, 2020
@mattmoor mattmoor deleted the multi-error branch December 17, 2020 14:27
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.

Consider dropping multierror
3 participants