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
In this example, Error is defined on the concrete testError type (instead of the more idiomatic pointer receiver). Below, matching the error starting with a pointer and then indirecting that pointer in the errors.As call won't work, because the pointer given to errors.As is to a *testError (not satisfying the Error interface) instead of testError. It seems like a lint could be added that checks for this case.
go vet has the -errorsas analysis, but doesn't catch this case, and I'm not currently finding prior art on a lint of this type. (It could be not possible due to something I'm not thinking of.)
For a concrete example, I was recently bit by this while doing an error.As check on an http2.StreamError, which implements Error on the concrete type.
The text was updated successfully, but these errors were encountered:
go.dev/play link
In this example,
Error
is defined on the concretetestError
type (instead of the more idiomatic pointer receiver). Below, matching the error starting with a pointer and then indirecting that pointer in theerrors.As
call won't work, because the pointer given toerrors.As
is to a*testError
(not satisfying theError
interface) instead oftestError
. It seems like a lint could be added that checks for this case.go vet
has the-errorsas
analysis, but doesn't catch this case, and I'm not currently finding prior art on a lint of this type. (It could be not possible due to something I'm not thinking of.)For a concrete example, I was recently bit by this while doing an
error.As
check on anhttp2.StreamError
, which implementsError
on the concrete type.The text was updated successfully, but these errors were encountered: