Skip to content

Detect streamed ClickHouse exceptions#132

Merged
KeKs0r merged 2 commits into
mainfrom
marc/clickhouse-streamed-exceptions
May 27, 2026
Merged

Detect streamed ClickHouse exceptions#132
KeKs0r merged 2 commits into
mainfrom
marc/clickhouse-streamed-exceptions

Conversation

@KeKs0r
Copy link
Copy Markdown
Member

@KeKs0r KeKs0r commented May 27, 2026

Summary

  • add ClickHouseStreamedException for non-zero x-clickhouse-exception-code response headers
  • check streamed exception headers after command/query/queryJson/insert calls
  • cover command, query, insert, and structured error behavior with tests

Verification

  • bun test packages/clickhouse/src/index.test.ts

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9700fca6a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/clickhouse/src/index.ts Outdated
@@ -517,6 +585,11 @@ export function createExecutorWithClient(
...(settings ? { clickhouse_settings: settings } : {}),
})
const rows = await result.json<T>()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check streamed error headers before decoding query body

In query() (and the same pattern in queryJson()), the code calls result.json() before assertStreamedQuerySucceeded(). With send_progress_in_http_headers=1, ClickHouse can return HTTP 200, set X-ClickHouse-Exception-Code, and then append a plain-text exception block to the body; in that case JSON decoding may throw first and header-based detection is never reached, so the new streamed-exception handling is bypassed. Move the header assertion ahead of body parsing so these failures are consistently surfaced as ClickHouseStreamedException.

Useful? React with 👍 / 👎.

ClickHouse can return HTTP 200, set x-clickhouse-exception-code, then
append a plain-text exception block after partial JSON rows when
send_progress_in_http_headers=1. Decoding the body first would throw on
the trailing non-JSON content before the header check ran, bypassing
ClickHouseStreamedException. Assert headers first in query() and
queryJson(), with a regression test that fails .json() to prove the
header check runs first.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@KeKs0r KeKs0r merged commit 95e6dbb into main May 27, 2026
6 checks passed
@KeKs0r KeKs0r deleted the marc/clickhouse-streamed-exceptions branch May 27, 2026 07:31
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