Re: [go-nuts] errors.Is and pointer arguments

2020-11-27 Thread Arve Knudsen
Thanks, Jan, but the error type in question is 3rd party so can't be
extended with Is() :)

Best,
Arve

On Fri, Nov 27, 2020 at 3:00 PM Jan Mercl <0xj...@gmail.com> wrote:

> On Fri, Nov 27, 2020 at 2:46 PM Arve Knudsen 
> wrote:
>
> > I've noticed that errors.Is returns false if you compare two error
> instances that are implemented as pointers. I.e., I'm using a struct where
> the Error method has a pointer receiver, and when passing struct instance
> pointers to errors.Is, it ends up comparing them by pointer address. Please
> see my example to see what I mean.
> >
> > Is this a bug in errors.Is or is it actually supposed to work this way?
> It really took us by surprise, and we ended up having to use errors.As
> instead since it does handle this case.
> >
> > For reference, I've already made a patch to errors.Is that changes it to
> support pointer arguments :)
>
> Alternatively https://play.golang.org/p/dUgL3IuMgY5
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEDa093fUKch%2BxoWcWYg-DNZea7w1Op-iZk407mnqAUzC8HbrQ%40mail.gmail.com.


[go-nuts] Re: errors.Is and pointer arguments

2020-11-27 Thread Arve Knudsen
Actually, never mind about this. I realized in the meantime that I 
shouldn't be using `errors.Is` in this case, where I basically want to see 
if the error is of a certain type. `errors.As` makes more sense for this 
use case.

On Friday, November 27, 2020 at 2:46:36 PM UTC+1 Arve Knudsen wrote:

> Hello!
>
> I've noticed that errors.Is returns false if you compare two error 
> instances that are implemented as pointers. I.e., I'm using a struct where 
> the Error method has a pointer receiver, and when passing struct instance 
> pointers to errors.Is, it ends up comparing them by pointer address. Please 
> see my example <https://play.golang.org/p/wSlpWrzP7hH> to see what I mean.
>
> Is this a bug in errors.Is or is it actually supposed to work this way? It 
> really took us by surprise, and we ended up having to use errors.As instead 
> since it does handle this case.
>
> For reference, I've already made a patch to errors.Is that changes it to 
> support pointer arguments :)
>
> Best,
> Arve
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c2ac60e5-d8a5-4e27-a307-97ade8f169fbn%40googlegroups.com.


[go-nuts] errors.Is and pointer arguments

2020-11-27 Thread Arve Knudsen
Hello!

I've noticed that errors.Is returns false if you compare two error 
instances that are implemented as pointers. I.e., I'm using a struct where 
the Error method has a pointer receiver, and when passing struct instance 
pointers to errors.Is, it ends up comparing them by pointer address. Please 
see my example  to see what I mean.

Is this a bug in errors.Is or is it actually supposed to work this way? It 
really took us by surprise, and we ended up having to use errors.As instead 
since it does handle this case.

For reference, I've already made a patch to errors.Is that changes it to 
support pointer arguments :)

Best,
Arve

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/83c4aa33-fd73-498d-ac03-d5b1585204d1n%40googlegroups.com.