-
-
Notifications
You must be signed in to change notification settings - Fork 194
Avoid returning an error for null document #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
@@ -1892,7 +1892,7 @@ func (d *Decoder) parse(ctx context.Context, bytes []byte) (*ast.File, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
if v != nil { | |||
if v != nil || (doc.Body != nil && doc.Body.Type() == ast.NullType) { |
There was a problem hiding this comment.
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 ReportAll modified and coverable lines are covered by tests ✅
❗ 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:
|
"v: ~", | ||
map[string]interface{}{"v": nil}, | ||
source: "~", | ||
value: (*struct{})(nil), |
There was a problem hiding this comment.
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.
Thank you for your great PR !! LGTM 👍 |
Closes #711
When a YAML document is
null
or~
, instead of returningio.EOF
, I believe decode.Decode should decode the value into nil, which is also compatible with go-yaml/yaml.