Re: [go-nuts] How to use errors.As with sentinel errors?

2021-08-04 Thread Andreas Götz
Opened https://github.com/golang/go/issues/47528 On Monday, August 2, 2021 at 6:30:04 PM UTC+2 Andreas Götz wrote: > > Because both are of type `*errors.errorString`, so the types match and > it copies over the value. > Arguably, `errors.errorString` should implement `As()` and return `false`,

Re: [go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread Andreas Götz
> Because both are of type `*errors.errorString`, so the types match and it copies over the value. Arguably, `errors.errorString` should implement `As()` and return `false`, unless the pointers match. I suggest filing an issue. Will do. It could also be a vet check to highlight errors.As used on

Re: [go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread 'Axel Wagner' via golang-nuts
On Mon, Aug 2, 2021 at 10:02 AM cpu...@gmail.com wrote: > Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically > > var Err = errors.New("sentinel") > err := errors.New("foo") > if errors.As(err, &Err) { > fmt.Println("why?") > } > > I'm wondering why this matches the sentinel

[go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread cpu...@gmail.com
Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically var Err = errors.New("sentinel") err := errors.New("foo") if errors.As(err, &Err) { fmt.Println("why?") } I'm wondering why this matches the sentinel error, or rather how to properly use sentinel errors. errors.As says "An