Skip to content

Upgrade gopkg.in/yaml.v2 to go.yaml.in/yaml/v4 - #654

Merged
bluekeyes merged 2 commits into
palantir:developfrom
andygrunwald:andygrunwald/upgrade-go-yaml-v4
Nov 9, 2026
Merged

bluekeyes merged 2 commits into
palantir:developfrom
andygrunwald:andygrunwald/upgrade-go-yaml-v4

Conversation

@andygrunwald

@andygrunwald andygrunwald commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • unknown fields and duplicate keys are rejected
  • only the first document is decoded

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.

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>
@changelog-app

changelog-app Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Use go.yaml.in/yaml/v4 for YAML parsing

Check the box to generate changelog(s)

  • Generate changelog entry

@bluekeyes bluekeyes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread appconfig/yaml.go Resolved
@changelog-app

changelog-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

✅ Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

💡 Improvements

  • Use go.yaml.in/yaml/v4 for YAML parsing (#654)

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
bluekeyes merged commit c00d1b3 into palantir:develop Nov 9, 2026
6 checks passed
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.

2 participants