Repository navigation
fix(client-v2): throw on in-band server exception row in JSONEachRowFormatReader - #3313
pcbeingused333 wants to merge 5 commits into
Conversation
…ormatReader
With http_write_exception_in_output_format a query that fails after the
response started ends with an extra {"exception": "Code: ..."} row. The
reader now throws ServerException from next() for that row instead of
returning it as data.
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
chernser
left a comment
There was a problem hiding this comment.
thank you for the contribution!
please see comments.
It is better to have this handling on JSON library exception. May be remembering last raw line would help.
Current implementation will degrade performance.
AI review gate — the gate never ran on this headThe org-required gate workflow has no run on What to do: a maintainer runs History (latest 5 heads, newest first)
|
…wFormatReader Address review: the check is off by default (new constructor flag), the schema decision is made once, error code parsing moves to ClientUtils with -1 for unreadable codes, and the key is a constant.
…body hasServerErrorCode requires a Code: or Error: prefix, a numeric code, and an Exception marker, so a value such as "Code: 1 is a value" stays data. JSONEachRowServerExceptionIT reads a ClickHouse 25.8 HTTP 200 body (data rows, then the exception object) with Gson and Jackson.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 5f4a7d4. Configure here.
AI review gate — AI review passedClean review from: Cursor Bugbot. |
|
Thanks for the review. I pushed an update. Detection is off by default. You have to use When the option is on, a row is treated as an error only if it has exactly one entry, the key is
If the result schema is a single String column named The one-argument constructor is unchanged and doesn't inspect rows. jdbc-v2 Reproduction on ClickHouse 25.8: SELECT toInt32(number) AS id FROM numbers(100)
WHERE throwIf(number = 50, 'in-band-boom') = 0
SETTINGS http_write_exception_in_output_format = 1, max_block_size = 1
FORMAT JSONEachRowTests:
This change was prepared with the assistance of an AI tool (Claude). |
ConnectorSec security review — head
|
chernser
left a comment
There was a problem hiding this comment.
please resolve the issue #3313 (comment)
- use client itself not an URLConnection
- exclude test from cloud by throwing
SkipException
…n IT With a compressed response the server buffers the body and answers with an HTTP 500, so no in-band exception row is streamed. Also drop a stale javadoc.
|
Thanks, both points addressed in 3c663ad: the integration test now reads the body through This comment was drafted with Claude Code. |

Fixes #3220
Cause: with
http_write_exception_in_output_format(default on, 25.8), a query that fails after the response started makes the server append{"exception": "Code: ..."}as one more JSONEachRow row and end the body normally.JSONEachRowFormatReaderhanded it out as an ordinary data row, so the failure was silent (truncated result plus an all-null row).Fix: when the prefetched row has exactly one key,
exception, with a string value starting withCode:, it is turned into aServerException(code parsed fromCode: N., as the issue's expected behaviour asks) through the existing deferred-error path (the valid preceding rows are still returned, the error surfaces on the nextnext()). Rows with other columns are untouched, and so is a query whose whole result is a singleexceptioncolumn (detected from the schema inferred from the first row), even when its values start withCode:. A query that selectsexceptionnext to other columns (e.g.SELECT query_id, exception FROM system.query_log) is still protected, since JSONEachRow writes every column in every row and a one-key row cannot be data there.Compatibility: previously such a row was returned as data; it now throws from
next(). Queries whose only column isexceptionare unaffected.jdbc-v2(StatementImpl) uses the same reader, so it gets the same behaviour. Addedhistory/latest/3220.mdand a line indocs/features.md.Tests:
JSONEachRowFormatReaderTestadds a case for the in-band error row (fails before, passes after), a case with a multi-column schema that includesexception, and ones confirming that queries with only anexceptioncolumn (including values likeCode: 60. DB::Exception...) are not treated as errors.This change was prepared with the assistance of an AI tool (Claude) and reviewed before submission.
Note
Low Risk
Behavior change is opt-in and scoped to JSONEachRow reading; default callers (including jdbc-v2’s one-arg constructor) are unchanged.
Overview
Adds opt-in handling (
new JSONEachRowFormatReader(parser, true), default unchanged) for ClickHouse’s streamed JSONEachRow failure row{"exception": "Code: ..."}whenhttp_write_exception_in_output_formatappends it after normal data rows.When enabled, matching rows are not returned as data:
next()throwsServerExceptionwith the parsed code via newClientUtils.parseServerErrorCode/hasServerErrorCode, while rows already read are still delivered. Detection is skipped if the inferred schema is only a String column namedexception, so legitimate single-columnexceptionqueries stay data.Unit, integration (
JSONEachRowServerExceptionIT), and documentation/changelog entries cover the behavior.Reviewed by Cursor Bugbot for commit e7dc0e6. Bugbot is set up for automated code reviews on this repo. Configure here.