#202 - Fix XmlReaderTask - #213
Merged
Merged
Conversation
…Exception` on an empty file or invalid XML (with the libxml error messages) instead of a `ValueError` or a silent empty `\DOMDocument`. Update documentation, add tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… may return a stale size from the stat cache for a file just written Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #202.
XmlReaderTask(throughCleverAge\ProcessBundle\Filesystem\XmlFile::read()) does not handle bad input files:ValueError: SplFileObject::fread(): Argument #1 ($length) must be greater than 0.DOMDocument::loadXML()is ignored. Only a PHP warning is raised, and an empty\DOMDocument(documentElement=null, no child nodes) is passed to the next tasks. In debug mode the Symfony error handler turns the warning into an exception, so the process fails; without debug (production), the process goes on silently with an empty document.This PR:
\UnexpectedValueException('XML file "<path>" is empty');loadXML()runs withlibxml_use_internal_errors(true); the collected libxml errors are cleared and the previous setting is restored;\UnexpectedValueException('Invalid XML in file "<path>": <libxml message> (line L, column C); ...')is thrown; libxml warnings are still tolerated;XmlReaderTaskreference documentation (Notes), add unit tests forXmlFile.The new regression tests fail on
mainand pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.Requirements
Breaking changes
Bug fix:
XmlReaderTasknow throws an\UnexpectedValueExceptionwhen the XML is invalid, instead of passing an empty or partial\DOMDocumentto the next tasks with only a PHP warning. This includes XML that parses but has libxml errors, such as an undefined namespace prefix (<root><x:a/></root>), which used to give a partial document. An empty file now throws an\UnexpectedValueExceptioninstead of a\ValueError. Processes relying on the silent empty document (e.g. in production, without the Symfony debug error handler) will now fail at the reader task: useerror_strategyto handle these files.🤖 Generated with Claude Code