Repository navigation
Avoid nil type panic when decoding Struct YAML - #34
Draft
Kayvan-Zahiri wants to merge 1 commit into
Draft
Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Decoding YAML into a zero-valued
serpent.Struct[any]panics:reflect.TypeOf(s.Value)is nil, so callingKind()fails before the YAML decoder can initialize the value. Mapping, sequence, and scalar inputs all reproduce this through the publicyaml.UnmarshalAPI.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
go test -timeout=3m -race ./...passes, including all examples and completion packages that have no tests.gofmtandgit diff --checkpass.go vet ./...reports three existing loop-capture diagnostics atvalues_test.go:111,:113, and:119. Running with unchangedvalues.goproduces 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.