Better error messages reading PIDX and PDSC files#721
Conversation
…s are read. Now with file name.
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on Modified Files with Diff Coverage (2)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
There was a problem hiding this comment.
Pull request overview
This PR improves error messages when reading PIDX and PDSC XML files by wrapping errors with the relevant filename, so users can identify which file caused the problem. It also provides a clearer message for empty files (EOF "too early").
Changes:
- Error wrapping logic added to
PdscXML.Read(),PidxXML.Read(), andPidxXML.CheckTime()to include filenames in error messages, with guards against double-wrapping. - Existing tests updated from
assert.Equaltoassert.Containsto accommodate the now-enriched error messages, plus new tests covering the wrapping behavior. - New
MalformedPack.pdsctest fixture added.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cmd/xml/pdsc.go | Wraps ReadXML errors with filename context in PdscXML.Read() |
| cmd/xml/pidx.go | Wraps ReadXML errors with filename context in PidxXML.Read() and CheckTime() |
| cmd/xml/pdsc_test.go | New tests for PDSC error wrapping (XML errors, EOF, nonexistent files) |
| cmd/xml/pidx_test.go | New tests for PIDX error wrapping (XML errors, EOF, double-wrapping, CheckTime) |
| cmd/installer/root_test.go | Loosened assertion from Equal to Contains for enriched error messages |
| cmd/installer/root_pdsc_add_test.go | Loosened assertion from Equal to Contains for enriched error messages |
| testdata/MalformedPack.pdsc | New malformed PDSC test fixture |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR improves error messages when reading malformed PIDX and PDSC XML files by wrapping XML parsing errors with the filename in ReadXML. It also adds special handling for EOF errors (empty files) with a "too early" annotation.
Changes:
ReadXMLincmd/utils/utils.gonow wrapsdecoder.Decodeerrors with the file path, and annotates EOF errors with "too early"- Existing tests are updated from
assert.Equaltoassert.Containsto accommodate the new error prefix - New tests verify filename presence in errors, no double-wrapping, and EOF handling for both PIDX and PDSC paths
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/utils/utils.go | Core change: wraps XML decode errors with the file path |
| cmd/xml/pdsc.go | Refactored Read() to explicit if/err pattern (functionally identical) |
| cmd/xml/pidx_test.go | New tests for error wrapping in PIDX Read and CheckTime |
| cmd/xml/pdsc_test.go | New tests for error wrapping in PDSC Read |
| cmd/utils/utils_test.go | Updated assertion from Equal to Contains |
| cmd/installer/root_test.go | Updated assertion from Equal to Contains |
| cmd/installer/root_pdsc_add_test.go | Updated assertion from Equal to Contains |
| testdata/MalformedPack.pdsc | New malformed PDSC test fixture |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
jkrech
left a comment
There was a problem hiding this comment.
I assume that an empty file would report the same error.
Note: If the file is empty, this is not even an xml file and we should not report an XML syntax error, right?
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
In case of an empty file the error message would be E: filename: EOF too early |
|
Why not being precise and writing that the file is empty? |
|
For that we would need an extra check before calling the XML decoder. The file is opened and then the XML decoding is called which returns EOF in case where it appears before the syntactically end of that file. |
|
I don't find it particularly helpful when the three of us make changes to the same source code simultaneously. |
Fully agree, please note I didn't touch the code, I've just answered the request for review. |
Regardless of the request, it seems the PR is not yet ready for review.

Fixes
Changes
Checklist