Repository navigation
Upgrade gopkg.in/yaml.v2 to go.yaml.in/yaml/v4 - #654
Merged
bluekeyes merged 2 commits intoNov 9, 2026
Merged
Conversation
gopkg.in/yaml.v2 is no longer maintained; go-yaml development moved to the YAML organization, which released go.yaml.in/yaml/v4 v4.0.0 as its stable line. v4 has no UnmarshalStrict, so the strict call sites use the classic Decoder API with KnownFields(true) instead, which keeps v2's strict behaviour: unknown fields and duplicate keys are rejected, and only the first document is decoded. The test helper keeps yaml.Unmarshal. The one difference is empty or comments-only input: v2 returned no error and left the struct empty, the decoder returns io.EOF. In YAMLRemoteRefParser both cases already end in "not a remote reference" (nil, nil), so callers see no change. The example's ReadConfig now rejects an empty config file instead of starting with zero values. go mod tidy drops gopkg.in/yaml.v2 and its test-only dependencies (gopkg.in/check.v1, kr/pretty, rogpeppe/go-internal). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generate changelog in
|
bluekeyes
reviewed
Nov 7, 2026
bluekeyes
left a comment
Contributor
There was a problem hiding this comment.
Thanks for proposing this upgrade. Since use here is limited to parsing only, I think this should be safe. I vaguely remember there being some issue with v3, maybe around alias handling, where it differed from v2, but hopefully that's been resolved.
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview💡 Improvements
|
Review feedback: since replacing UnmarshalStrict needs a code change either way, use v4's Load API with options rather than building a Decoder. WithV2Defaults and WithKnownFields keep v2's strict behaviour (unknown fields and duplicate keys are rejected). YAMLRemoteRefParser also passes WithSingleDocument. Load rejects input with more than one document by default, while UnmarshalStrict used the first one, so without it a remote reference followed by a second document would no longer be recognized. Checked against v2 for valid, unknown-field, duplicate-key, empty, comments-only, multi-document, null, aliased, anchored and merge-key input: all results match. The example's ReadConfig reverts the variable rename the Decoder needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bluekeyes
approved these changes
Nov 9, 2026
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.
Before this PR
gopkg.in/yaml.v2 is no longer maintained.
After this PR
gopkg.in/yaml.v2 is no longer maintained; go-yaml development moved to the YAML organization, which released go.yaml.in/yaml/v4 v4.0.0.
See https://github.com/yaml/go-yaml/releases/tag/v4.0.0
v4 has no UnmarshalStrict, so the strict call sites use the classic Decoder API with KnownFields(true) instead, which keeps v2's strict behaviour:
Possible downsides?
Empty or comments-only input: v2 returned no error and left the struct empty, the decoder returns io.EOF. In YAMLRemoteRefParser both cases already end in "not a remote reference" (nil, nil), so callers see no change.
The example's ReadConfig now rejects an empty config file instead of starting with zero values.
Note
AI assisted PR.