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
Both of these functions call If which does a traversal of the causal chain, it does not traverse the full tree. Specifically, If internally calls UnwrapOnce and doesn't handle the multi-error case, whereas functions like Is and As separately handle the multi-error case.
This leads to counter-intuitive behavior; you can have a value x of type T, and errors.Is(err, x) may be true, but errors.HasType(err, T{}) may fail.
Both of these functions call
If
which does a traversal of the causal chain, it does not traverse the full tree. Specifically,If
internally callsUnwrapOnce
and doesn't handle the multi-error case, whereas functions likeIs
andAs
separately handle the multi-error case.This leads to counter-intuitive behavior; you can have a value
x
of typeT
, anderrors.Is(err, x)
may be true, buterrors.HasType(err, T{})
may fail.I noticed this behavior while trying to add property-based tests to better understand the behavior of
HasType
here. https://github.com/sourcegraph/sourcegraph/pull/62992It would be valuable to either:
If
to traverse the full treeHasType
andHasInterface
HasType
andHasInterface
's docs which describe the behavior in the presence of multi-errors.The text was updated successfully, but these errors were encountered: