cockroachdb / cockroachdb/errors

Behavior of HasType and HasInterface is counter-intuitive

Ouverte
#145 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
2.5k
Forks
74
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Both of these functions call [`If`](https://sourcegraph.com/github.com/cockroachdb/errors@698c58cf81c4112204c35173983e95f2c7725de2/-/blob/markers/markers.go?L132-145) 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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez dans markers/markers.go, en particulier avec If et son utilisation de UnwrapOnce, puis comparez le comportement de parcours de HasType et HasInterface avec celui de Is et As pour les multi-erreurs. Examinez le contexte des tests basés sur les propriétés dans Sourcegraph PR 62992. Le travail est considéré comme terminé lorsque la différence de parcours est résolue ou documentée et qu’une couverture est ajoutée pour le comportement choisi.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
go
Domaine
backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.