go: closed discriminated union UnmarshalJSON panics on JSON null

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

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, terraform
Ambito
tooling

Direzione di ricerca

Start at templates/templates/go/union.go.stmpl: compare the dis == nil guard emitted for open unions around line 225 with the closed-union discriminator switch. Reproduce with a closed union used as a required field whose JSON value is null, then make the closed path reset the union and return a descriptive error instead of dereferencing dis. Done means the template change plus regenerated review fixtures for Go, CLI and the Terraform provider all show the new behavior.

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

Descrizione

bug go terraform

Summary

The Go union template (templates/templates/go/union.go.stmpl) unmarshals the discriminator with json.Unmarshal(data, &dis) where dis is a pointer. When the input is JSON null, dis is set to nil and switch dis.<Field> dereferences it. The dis == nil guard is only emitted for open unions (line 225), so every closed discriminated union generated for Go, CLI, and Terraform can nil-deref.

Repro

Any closed discriminated union used as a required (non-pointer) field, with the server returning null for that field. For pointer fields encoding/json short-circuits to nil without calling UnmarshalJSON, so the required-field case is the one that reaches the switch.

Expected

Closed unions should treat null like an unknown discriminator: reset the union and return a descriptive error rather than panicking.

Scope

Shared template, so the fix lands in Go, CLI, and the Terraform provider SDK at once and regenerates the review fixtures for each.

Lingua principale
Go
Stelle
37
Fork
12
Merge medio
2g 1h
PR unite (30g)
67

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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.

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.