fix(node): return an error instead of panicking on a zero-field JSON schema - #3112
fix(node): return an error instead of panicking on a zero-field JSON schema#3112phil-opp wants to merge 1 commit into
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
e8f4d6a to
6496683
Compare
…schema Both JSON->Arrow readers finished with `batch.column(0).to_data()`. `RecordBatch::column(0)` indexes out of bounds and panics when the batch has no columns. In `read_json_value_as_arrow` the `schema` is caller-supplied — e.g. inferred from an empty JSON array via `infer_json_schema_from_iterator` in the node integration-testing harness — so a degenerate zero-field schema is reachable and turns a bad input into a panic. The sibling `read_from_json_with_schema` always sees the `"inner"` field injected by `wrapped()` (so it has a column in practice), but is guarded the same way for consistency and defense in depth. Extract a shared `first_column_data` helper that returns an `eyre::Result` error for a zero-column batch, and call it from both readers. Two unit tests cover the zero-field (Err, no panic) and normal single-field (round-trip) cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PYiYgEo2WKBXfGooqP2WG5
6496683 to
3752e55
Compare
|
🤖 Automated review by Claude — this is a fully automated review with no human in the loop. Treat it as advisory. Reviewed the diff — no issues found. Swapping Minor test note: Generated by Claude Code |
Issue
read_json_value_as_arrow(apis/rust/node/src/daemon_connection/json_to_arrow.rs) ended with:RecordBatch::column(0)indexes out of bounds and panics when the batch has no columns. This is apub fnwhoseschemais caller-supplied, and a zero-field schema is reachable: the node integration-testing harness (node_integration_testing.rs) builds the schema viainfer_json_schema_from_iterator(...)when nodata_typeis given, and an empty JSON array infers a schema with no fields. That degenerate-but-valid input turns into a panic instead of a recoverable error. (The siblingread_from_json_with_schemais unaffected — itswrapped()always injects an"inner"field, guaranteeing ≥1 column.)Fix
Use
batch.columns().first().context(...)?so a zero-column batch returns aneyre::Resulterror rather than panicking:Validation
New unit tests cover: a zero-field schema returns
Err(no panic), and a normal single-field schema still round-trips.origin/mainbefore opening. Please review carefully before merging.🤖 Generated with Claude Code
Generated by Claude Code