cockroachdb / errors

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

errbase: prevent a call cycle for Formatter/SafeFormatter errors #90

Closed knz closed 2 years ago

knz commented 2 years ago

Fixes #88.

We've found a need somewhere to implement an Error() method on a leaf by delegating the behavior to the Formatter or SafeFormatter interfaces. In that case, the errors.IsAny call inside the special handler causes a call cycle.

This commit breaks the cycle by handling the special cases after the interfaces.

A possible regression would be that one of the stdlib errors starts implementing fmt.Formatter, whereby we'd lose the special handling (which, as of this writing, extracts safe strings). At the time of this writing, none of the stdlib errors of interest implement fmt.Formatter, so we're punting dealing with that when/if it arises in the future.


This change is Reviewable

tbg commented 2 years ago

Thanks! It would take me a long time to really scrutinize the changes to the control flow and I have not attempted to do that. However, I see how you're solving the problem and how the test cases demonstrate that.

knz commented 2 years ago

Thanks!