go: closed discriminated union UnmarshalJSON panics on JSON null

Abierto
#239 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go, terraform
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
37
Forks
12
Merge medio
2 d 1 h
PR fusionados (30 d)
67

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.