News for hackers. Stuff that matters.
Re:Structured Errors in Go by zarldev on Monday June 02, 2025 @04:33AM (#44156779)
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??
Re:Structured Errors in Go by arccy on Monday June 02, 2025 @04:37AM (#44156803)
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.

Re:Structured Errors in Go by zarldev on Monday June 02, 2025 @04:38AM (#44156811)
I stand corrected. Still you cannot implement an Is on a sentinel error and is only applicable to concrete error types. And if I'm using concrete types I'm going to us errors.As