Re:Structured Errors in Go
by arccy on Sunday June 01, 2025 @07:27AM
(#44150109)
in standard go you'd have errors implement:
and it can match different sentinel errors.
Or you can make your own wrapper to have the error chain match.
[ Parent
| on HN ]
In standard go you would not implement Is but would use the errors.Is call. How would this work if it is a sentinel error as you would use with errors.Is??
https://pkg.go.dev/errors#Is
> An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
by default errors.Is matches the exact error variable, but you can use it to match other errors as well.