Skip to content

Handle empty stdin in streaming csvjson - #1402

Open
eggbiscuit wants to merge 1 commit into
wireservice:masterfrom
eggbiscuit:fix/csvjson-empty-stream
Open

eggbiscuit wants to merge 1 commit into
wireservice:masterfrom
eggbiscuit:fix/csvjson-empty-stream

Conversation

@eggbiscuit

Copy link
Copy Markdown

csvjson --stream --no-inference --snifflimit 0 raises StopIteration and exits 1 when stdin is empty. An upstream filter that selects zero records can therefore fail an otherwise valid NDJSON pipeline. The buffered --stream path already emits nothing and exits successfully for the same input.

Reproduce on master at 43d09bf1f39382bc2d66c4f892c9814901179ff8:

printf '' | csvjson -v --stream --no-inference --snifflimit 0

Give the header read an empty default so an exhausted input produces zero output records and exits 0. Regression coverage checks empty stdin and empty-file controls with and without --no-header-row. Both stdin subtests fail with StopIteration before the runtime change and pass afterward.

Validated locally on macOS arm64, Python 3.12.13, agate 1.14.2:

  • pytest --cov csvkit -q — 368 passed, 4 skipped, 35 subtests passed.
  • flake8 . --exclude .venv, isort . --check-only, and git diff --check pass.
  • check-manifest --no-build-isolation passes.
  • Direct CLI checks confirm empty stdout/stderr and exit 0 for empty stdin in both header modes.

This touches the same header-reading line refactored by #1394. When combining the changes, retain the empty-input handling alongside that PR's first-record preservation.

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.

1 participant