Hacker News new | ask | show | jobs
by peacelilly 1283 days ago
The secret to wrapping errors is the erros.As and errors.Is special interfaces called out only in the documentation: https://pkg.go.dev/errors#Is

You must build a Directed Acyclic Graph (DAG) to ensure these special interfaces don't hit an infinite loop.

To stop the infinite loop cycles, and actually implement a DAG, I marked visited nodes and returned `false` if the nodes were already marked.

1 comments

If you’re needing to implement this I’d highly suggest your code could be restructured to eliminate the issues. This is a code smell.

I’ve been using errors.Is since day one and have never once needed to implement anything like you described. I define sentinel errors in my root “business logic and types” package, and my child packages use those special errors in their own error Is() methods.