cockroachdb / errors

Go error library with error portability over the network
Apache License 2.0
2.07k stars 66 forks source link

secondary: add SummarizeErrors variadic method #96

Open HonoreDB opened 2 years ago

HonoreDB commented 2 years ago

I was recently debugging a workflow with lots of async workers able to cancel each other, so that by the time an error bubbled up it was ambiguous where the longest stack would be and whether there were errors in two places because one wrapped the other or because of two separate root errors. I felt like what would be most convenient would be to smoosh everything together rather than try to be too smart about it.

This PR implements SummarizeErrors, which is mainly the generalization of CombineErrors over n errors. If one argument is detectably already wrapping another, the result will ignore the latter. If two errors are distinct but both wrapping the same error, the result will preserve that information. Two errors are distinct if err1 != err2; there didn't look to be much benefit in bringing in things like .Is as we're really interested in identity, not equivalence.

This is an unsolicited spike; feel free to bikeshed details or reject out of hand.


This change is Reviewable

cockroach-teamcity commented 2 years ago

CLA assistant check
All committers have signed the CLA.

knz commented 2 years ago

Hi sorry I did not see this earlier. Just for reference, can you show us where this would be used?

HonoreDB commented 2 years ago

Sure, the file that motivated this is https://github.com/cockroachdb/cockroach/blob/master/pkg/ccl/changefeedccl/sink_pubsub.go#L272 . I've linked one line in particular where I'm calling CombineErrors on the output of another function in the same file that also calls CombineErrors. It's a flow where errors can be encountered and persisted in different ways at different points by workers, and then most of the exposed methods need to fail informatively if there's been an error in any of those places.

HonoreDB commented 2 years ago

Very non-urgent ping.