Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of HasType and HasInterface is counter-intuitive #145

Open
varungandhi-src opened this issue May 31, 2024 · 1 comment
Open

Behavior of HasType and HasInterface is counter-intuitive #145

varungandhi-src opened this issue May 31, 2024 · 1 comment

Comments

@varungandhi-src
Copy link

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.

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/62992

It would be valuable to either:

  • Change the implementation of If to traverse the full tree
  • OR Add a separate function which does a tree traversal (not just the "causal chain") and use that from HasType and HasInterface
  • OR Add a cautionary warning to HasType and HasInterface's docs which describe the behavior in the presence of multi-errors.
@varungandhi-src
Copy link
Author

It seems like this is basically the same kind of issue as #135, but for HasType and HasInterface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant