Skip to content

Conversation

@shuheiktgw
Copy link
Collaborator

Closes #711

When a YAML document is null or ~, instead of returning io.EOF, I believe decode.Decode should decode the value into nil, which is also compatible with go-yaml/yaml.

  • Describe the purpose for which you created this PR.
  • Create test code that corresponds to the modification
@shuheiktgw shuheiktgw requested a review from Copilot May 7, 2025 07:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the decode behavior to handle YAML documents that are explicitly null (using null or ~) by decoding them as nil instead of returning an error.

  • Adjusted conditional check in decode.go to include documents with a null type.
  • Added corresponding test code to ensure that a null document decodes correctly.
return nil, err
}
if v != nil {
if v != nil || (doc.Body != nil && doc.Body.Type() == ast.NullType) {
Copy link

Copilot AI May 7, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting the null-check logic into a helper function or clearly documenting the rationale inline to improve the readability and maintainability of the code.

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.92%. Comparing base (0203d69) to head (367a04a).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #721      +/-   ##
==========================================
+ Coverage   77.87%   77.92%   +0.05%     
==========================================
  Files          22       22              
  Lines        7986     7986              
==========================================
+ Hits         6219     6223       +4     
+ Misses       1352     1348       -4     
  Partials      415      415              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
"v: ~",
map[string]interface{}{"v": nil},
source: "~",
value: (*struct{})(nil),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for the large diff 🙇 This is the only new test case I added. I wanted to distinguish the io.EOF error from others, so I added an eof field to the test struct.

@goccy
Copy link
Owner

goccy commented May 7, 2025

Thank you for your great PR !! LGTM 👍

@goccy goccy merged commit 427b18e into master May 7, 2025
20 checks passed
@goccy goccy deleted the return_null branch May 7, 2025 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants