Repository navigation
fix: detect exceptions written as a JSON row - #493
Open
cristianchiriac wants to merge 1 commit into
Open
cristianchiriac wants to merge 1 commit into
cristianchiriac wants to merge 1 commit into
Conversation
Servers before 25.11 (no X-ClickHouse-Exception-Tag) write an error that
happens mid-stream into the output format. For JSON formats such as
JSONEachRow that is a final {"exception": "Code: ..."} row, which ends
with )"} and a newline rather than )) and a newline, so the response was
returned as data without an error.
Fixes ClickHouse#492
cristianchiriac
requested review from
abonander,
joe-clickhouse,
kavirajk and
peter-leonov-ch
as code owners
October 17, 2026 16:30
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #492.
On servers that don't send
X-ClickHouse-Exception-Tag(before 25.11, e.g. the 25.8 LTS line), an error raised after streaming has started is written into the output format. For JSON formats likeJSONEachRowthe last row is{"exception": "Code: 395. DB::Exception: ... (version 25.8.33.6 (official build))"}.extract_exception()only looked for the raw-text form, which ends with))+ newline, so this row ends up in the caller's data andfetch_bytes(...)finishes without an error.extract_exception()now also checks chunks ending with)"}+ newline:extract_exception_json()takes the last line, requires it to be{"exception": <JSON string>}, decodes the string withserde_json(so escaped quotes in the message come out right), and returnsError::BadResponsewhen it looks like a ClickHouse exception (Code:,DB::,Exception:), the same check as the raw-text path. Other rows are left alone.Changelog text: Fixed detection of mid-stream exceptions written as a JSON row (
{"exception": ...}) by servers without exception tagging.Checklist
it_extracts_exception_json_rowcovers the row from the issue, a message with escaped quotes, and a data row with anexceptionkey that isn't a ClickHouse exception. It fails without the change.cargo test --lib: 112 passed.cargo fmt --checkis clean;cargo clippy --lib --testsonly shows the two existingredundant reference in format!warnings in other files.