Skip to content

#202 - Fix XmlReaderTask - #213

Merged
njoubert-cleverage merged 3 commits into
mainfrom
202
Sep 28, 2026
Merged

njoubert-cleverage merged 3 commits into
mainfrom
202

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #202.

XmlReaderTask (through CleverAge\ProcessBundle\Filesystem\XmlFile::read()) does not handle bad input files:

  • Empty file: the task crashes with a low-level ValueError: SplFileObject::fread(): Argument #1 ($length) must be greater than 0.
  • Invalid XML: the result of 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:

  • an empty file throws an explicit \UnexpectedValueException('XML file "<path>" is empty');
  • loadXML() runs with libxml_use_internal_errors(true); the collected libxml errors are cleared and the previous setting is restored;
  • if the load fails, or libxml reports an error or a fatal error, an \UnexpectedValueException('Invalid XML in file "<path>": <libxml message> (line L, column C); ...') is thrown; libxml warnings are still tolerated;
  • update the XmlReaderTask reference documentation (Notes), add unit tests for XmlFile.

The new regression tests fail on main and pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

Bug fix: XmlReaderTask now throws an \UnexpectedValueException when the XML is invalid, instead of passing an empty or partial \DOMDocument to 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 \UnexpectedValueException instead 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: use error_strategy to handle these files.

🤖 Generated with Claude Code

njoubert-cleverage and others added 3 commits September 28, 2026 12:04
…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>
@njoubert-cleverage
njoubert-cleverage merged commit ac53294 into main Sep 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XmlReaderTask fails on an empty file and silently emits an empty DOMDocument on invalid XML

1 participant