go: closed discriminated union UnmarshalJSON panics on JSON null

オープン
#239 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, terraform
領域
tooling

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
37
フォーク
12
平均マージ
2日 1時間
マージ済み PR(30日)
67

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。