You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I expected to be able to use the xerrors.As using a literal argument like xerrors.As(testcase, &Err{})
What did you see instead?
xerrors.As(testcase, &Err{}) panics.
It seems like it's unwrapping the interface{} argument, deref-ing the pointer at the same time(*Err -> Err). The struct itself doesn't implement error, as the error interface was implemented using a pointer receiver. This causes input validation to fail and panic.
The text was updated successfully, but these errors were encountered:
This is working as intended. If Err implements the error interface with a pointer receiver, the type that implements it is *Err, so you have to pass a pointer to that (**Err) to xerrors.As. &Err{} gives you a value of type *Err, which is why your first call in the playground works (you're taking the address of an *Err, which is an **Err) but the second doesn't.
Is there any chance that we can have some documentation stating that xerrors.Is(x, y) being true doesn't imply that xerrors.As(x, y) would be true then? I realise the language doesn't work in a way that allows complete symmetry between these calls. However, in the api it looks like xerrors.Is(x, y) implies xerrors.As(x, y) whereas that's not the case.
I'm happy to throw together a PR for this if needed.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I believe so
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
See goplay link:
https://play.golang.org/p/NAROTLJUM9H
What did you expect to see?
I expected to be able to use the
xerrors.As
using a literal argument likexerrors.As(testcase, &Err{})
What did you see instead?
xerrors.As(testcase, &Err{})
panics.It seems like it's unwrapping the
interface{}
argument, deref-ing the pointer at the same time(*Err
->Err
). The struct itself doesn't implement error, as theerror
interface was implemented using a pointer receiver. This causes input validation to fail and panic.The text was updated successfully, but these errors were encountered: