Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Behavior of HasType and HasInterface is counter-intuitive

Aperta
#145 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Inizia in markers/markers.go, in particolare con If e il suo utilizzo di UnwrapOnce, quindi confronta il comportamento di attraversamento di HasType e HasInterface con quello di Is e As per i multi-errori. Esamina il contesto dei test basati sulle proprietà in Sourcegraph PR 62992. Il lavoro è completato quando la differenza nell’attraversamento è stata risolta o documentata e sono stati aggiunti test per il comportamento scelto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Go
Stelle
2.5k
Fork
75
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cockroachdb/errors

Tutte le issue di cockroachdb/errors

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.