Skip to content

#207 - Fix JsonStreamReaderTask / JsonStreamWriterTask - #218

Merged
njoubert-cleverage merged 2 commits into
mainfrom
207
Sep 28, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
207

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #207.

JsonStreamFile has two problems:

  1. Reader, scalar line: when a JSON Lines file contains a line that decodes to a scalar (42, "foo", true…), JsonStreamReaderTask crashes with a PHP TypeError coming from the ?array return type, without a useful message nor line number.
  2. Writer, missing directory: JsonStreamWriterTask fails when the parent directory of file_path does not exist, while CsvWriterTask creates it (see CsvFile).

This PR:

  • JsonStreamFile::readLine() checks the decoded value and throws an explicit \UnexpectedValueException naming the line number, the file path and the type found. The signature is unchanged and null lines are still skipped.
  • JsonStreamFile::__construct() creates the parent directory recursively, as CsvFile does, for non-read modes only (standard streams are skipped). JsonStreamWriterTask (and the --output option of cleverage:process:execute with the json-stream format) then work with a path whose directory does not exist yet.
  • Update the reference documentation, add unit tests.

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

None. A scalar line now throws an \UnexpectedValueException instead of a \TypeError.

🤖 Generated with Claude Code

… an explicit `\UnexpectedValueException` when a line decodes to a scalar, create the missing parent directory when writing. Update documentation, add tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit 9ac6829 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.

JsonStreamReaderTask / JsonStreamWriterTask: a scalar line raises a TypeError and the writer does not create the parent directory

1 participant