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

proposal: x/sync/errgroup: optionally collect all errors #72101

Closed
imjasonh opened this issue Mar 4, 2025 · 6 comments
Closed

proposal: x/sync/errgroup: optionally collect all errors #72101

imjasonh opened this issue Mar 4, 2025 · 6 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@imjasonh
Copy link

imjasonh commented Mar 4, 2025

Proposal Details

When using errgroup.Group, the current behavior is to fail and return the first error that's encountered. This works great. errgroup is consistently one of my favorite packages to use.

But, sometimes I want to collect and report all errors at the end.

Luckily, we have errors.Join to do just this!

I'd like to propose either an optional method to make errgroup collect errors, or a type/package/something to do what errgroup does, with this behavior.

I'm open to any naming or structure you folks would recommend, and I'd be happy to send a CL to implement it if there's interest.

@gopherbot gopherbot added this to the Proposal milestone Mar 4, 2025
@apparentlymart
Copy link

If I'm understanding correctly I think this is the same as what I asked in #57534 (comment), and the errgroup author responded in #57534 (comment) with a justification against this idea.

I don't have a strong feeling about this myself; I'm just sharing this to link the discussions together.

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Mar 4, 2025
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Mar 4, 2025
@ianlancetaylor
Copy link
Member

@apparentlymart I think this suggestion is slightly different. Rather than having a Wait method that joins together all the errors, we leave the Wait method doing what it does today: return the first error. The proposal here is a new method, WaitAll, that waits for all the errors and returns them joined together with errors.Join. That is, Wait is useful and we provide it today, and @bcmills was arguing that we should keep Wait. But having Wait behave as it does is not necessarily an argument against also providing WaitAll.

@seankhliao
Copy link
Member

There's a more recent objection to having a method get all of them
#57534 (comment) :

that would make the storage requirement of an errgroup O(N) with the number of tasks processed instead of O(1) as it is today.
In typical errgroup usage, all errors after the first will be caused by the cancellation triggered by the first error, and thus unreliable. Moreover, since Go calls may be made concurrently there is no obvious order of results, and thus no obvious way to collate them or correlate them with the associated Go calls.

@ianlancetaylor
Copy link
Member

Thanks, that is convincing. We aren't going to do this. @imjasonh This might be suitable for a different package, but it should probably start out as a third-party package rather than one in x/sync. Thanks.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2025
@imjasonh
Copy link
Author

imjasonh commented Mar 5, 2025

Thanks, I appreciate your consideration and discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
None yet
Development

No branches or pull requests

6 participants