fix: reuse parseDocs helper to avoid YAML split/unmarshal duplication - #204
Conversation
Greptile SummaryThe test now reuses the shared YAML document parser while preserving strict validation and document-index diagnostics.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "fix: reuse parseDocs helper to avoid YAM..." | Re-trigger Greptile |
| for _, raw := range splitYAMLDocuments(content) { | ||
| if strings.TrimSpace(raw) == "" { | ||
| continue | ||
| } | ||
| var doc map[string]any | ||
| err := yaml.UnmarshalStrict([]byte(raw), &doc) | ||
| require.NoErrorf(t, err, "file %s doc %d is not valid YAML:\n%s", name, i, raw) | ||
| require.NoErrorf(t, err, "%s contains a document that is not valid YAML (likely a glued separator):\n%s", name, raw) |
There was a problem hiding this comment.
Document index removed from diagnostics
When strict unmarshalling fails for a multi-document YAML file, parseDocs now reports the filename and raw YAML but not the document index, making similar multirail documents unnecessarily difficult to locate.
| for _, raw := range splitYAMLDocuments(content) { | |
| if strings.TrimSpace(raw) == "" { | |
| continue | |
| } | |
| var doc map[string]any | |
| err := yaml.UnmarshalStrict([]byte(raw), &doc) | |
| require.NoErrorf(t, err, "file %s doc %d is not valid YAML:\n%s", name, i, raw) | |
| require.NoErrorf(t, err, "%s contains a document that is not valid YAML (likely a glued separator):\n%s", name, raw) | |
| for i, raw := range splitYAMLDocuments(content) { | |
| if strings.TrimSpace(raw) == "" { | |
| continue | |
| } | |
| var doc map[string]any | |
| err := yaml.UnmarshalStrict([]byte(raw), &doc) | |
| require.NoErrorf(t, err, "file %s doc %d is not valid YAML (likely a glued separator):\n%s", name, i, raw) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Signed-off-by: andrewwhitecdw <andrewwhitecdw@users.noreply.github.com>
d9a9a94 to
2918013
Compare
|
@greptile-apps Good catch — I restored the document index in the |
|
Confirmed — require.NoErrorf(t, err, "file %s doc %d is not valid YAML (likely a glued separator):\n%s", name, i, raw)The document index is restored, the helper reuse is intact, and the error message is actually more precise than the original (which lacked the index entirely). LGTM. |
This PR addresses the following issue in
pkg/networkoperatorplugin/sriov_render_test.go: reuse parseDocs helper to avoid YAML split/unmarshal duplication.Changes
pkg/networkoperatorplugin/sriov_render_test.go: consolidate strict multi-document YAML parsing in the existingparseDocshelper while preserving the failing document index in error messages.Details
Greptile noted that the refactor removed the document index from
parseDocsdiagnostics, making it harder to locate the failing document in malformed multi-document YAML. The index is restored while keeping the helper reuse.Tests
Result: PASS
Contributor guidelines
Per this repo's CONTRIBUTING.md:
Signed-off-bytrailer, DCO).