Errors lose the cause and don't name the field

Aperta
#19 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Start with the named error paths in tt.go, converter.go, and mapper.go, then read tt_test.go:619 for the exact-message expectations. Use the reproduction snippets to check conversion failures, sequence errors, field context, and tuple-length errors. Done when the errors retain their causes and useful context, the relevant tests pass, and the user-visible message changes are documented in the CHANGELOG.

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

Descrizione

Reproduction snippets assume:

fac := tupleconv.MakeStringToTTConvFactory()

Where: MakeTypeToTTConverters (tt.go:295), MakeSequenceConverter (converter.go:77), Mapper.Map and validateTuple (mapper.go:27, mapper.go:50).

  • MakeTypeToTTConverters replaces the error with unexpected value %v for type %q: no %w, no field name or position, and %v makes an empty value invisible.
  • MakeSequenceConverter drops the errors of all the converters it tried.
  • Map doesn't say which field failed, and the length error has no lengths.

Reproduction:

convs, _ := tupleconv.MakeTypeToTTConverters[string](fac, []tupleconv.SpaceField{
	{Name: "id", Type: "unsigned"}, {Name: "count", Type: "unsigned"}})
_, err := tupleconv.MakeMapper(convs).Map([]string{"1", ""})
fmt.Printf("%q\n", err)
_, err = tupleconv.MakeMapper(convs).Map([]string{"1", "2", "3"})
fmt.Printf("%q\n", err)
_, err = fac.GetIntegerConverter().Convert("1.5")
fmt.Printf("%q\n", err)
"unexpected value  for type \"unsigned\""
"tuple length should be less or equal converters list length, when default converter is not used"
"unexpected value 1.5"

Suggested fix: wrap with %w and quote values with %q. Join the errors in MakeSequenceConverter with errors.Join. Name the field (SpaceField.Name and position) in MakeTypeToTTConverters. Wrap errors with the field index in Map, and put both lengths into the length error. A typed error (e.g. FieldError{Index, Name, Err}) would let callers handle it with errors.As. The messages are user-visible (tt_test.go:619 checks the exact text), so this needs a CHANGELOG entry.

Lingua principale
Go
Stelle
1
Fork
0
Merge medio
1h 43m
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 tarantool/go-tupleconv

Tutte le issue di tarantool/go-tupleconv

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.