go: closed discriminated union UnmarshalJSON panics on JSON null

Đang mở
#239 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, terraform
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
37
Fork
12
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
67

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.