Skip to content

Avoid nil type panic when decoding Struct YAML - #34

Draft
Kayvan-Zahiri wants to merge 1 commit into
coder:mainfrom
Kayvan-Zahiri:codex/avoid-nil-type-panic-yaml
Draft

Kayvan-Zahiri wants to merge 1 commit into
coder:mainfrom
Kayvan-Zahiri:codex/avoid-nil-type-panic-yaml

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

Problem

Decoding YAML into a zero-valued serpent.Struct[any] panics: reflect.TypeOf(s.Value) is nil, so calling Kind() fails before the YAML decoder can initialize the value. Mapping, sequence, and scalar inputs all reproduce this through the public yaml.Unmarshal API.

Change

Guard the dynamic type before applying the existing empty-slice compatibility handling. Values without a dynamic type proceed to n.Decode, which can initialize the interface normally. Existing empty-slice-to-nil behavior is preserved.

Validation

  • Three new mapping/sequence/scalar regression cases panic before the change and pass afterward.
  • An additional control confirms empty YAML sequences still clear existing slice values to nil.
  • go test -timeout=3m -race ./... passes, including all examples and completion packages that have no tests.
  • gofmt and git diff --check pass.
  • go vet ./... reports three existing loop-capture diagnostics at values_test.go:111, :113, and :119. Running with unchanged values.go produces the same diagnostics. These are not suppressed or changed here.

Tested locally with Go 1.27.0; the repository's CI Go 1.21 matrix has not been run locally. No hosted Coder usage is claimed.

AI assistance: OpenAI Codex assisted with the reproduction, patch, tests, and this description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant