Skip to content

[1.11.2] Add enhanced stack traces and a few more try-catch blocks #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2025

Conversation

slvrtrn
Copy link
Contributor

@slvrtrn slvrtrn commented Jun 3, 2025

Summary

Added a new configuration option: capture_enhanced_stack_trace; see the JS doc in the Node.js client package. Note that it is disabled by default due to a possible performance impact. For example:

Error: Timeout error.
    at async UserContext.<anonymous> (/home/serge/work/clickhouse-js/packages/client-node/__tests__/integration/node_foo.test.ts:9:7)
    at async ClickHouseClient.query (/home/serge/work/clickhouse-js/packages/client-common/src/client.ts:196:52)
    at async NodeHttpConnection.query (/home/serge/work/clickhouse-js/packages/client-node/src/connection/node_base_connection.ts:159:44)
    at Socket.onTimeout (/home/serge/work/clickhouse-js/packages/client-node/src/connection/node_base_connection.ts:661:35)
    at Object.onceWrapper (node:events:632:28)
    at Socket.emit (node:events:530:35)
    at Socket.emit (node:domain:489:12)
    at Socket._onTimeout (node:net:595:8)
    at listOnTimeout (node:internal/timers:594:17)
    at processTimers (node:internal/timers:529:7)

instead of previous:

Error: Timeout error.
    at Socket.onTimeout (/home/serge/work/clickhouse-js/packages/client-node/src/connection/node_base_connection.ts:659:35)
    at Object.onceWrapper (node:events:632:28)
    at Socket.emit (node:events:530:35)
    at Socket.emit (node:domain:489:12)
    at Socket._onTimeout (node:net:595:8)
    at listOnTimeout (node:internal/timers:594:17)
    at processTimers (node:internal/timers:529:7)

Should be released as a patch version helping to debug #410

@slvrtrn slvrtrn requested a review from mshustov June 3, 2025 17:36
@mshustov mshustov requested a review from Copilot June 4, 2025 07:33
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds enriched stack trace capture and augmentation utilities, integrating them into the NodeBaseConnection to improve error diagnostics.

  • Introduces getCurrentStackTrace and addStackTrace in the common error module
  • Wraps key error handlers in NodeBaseConnection to attach full call-site traces
  • Exports new utilities via the common package index

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/client-node/src/connection/node_base_connection.ts Captures a baseline stack and wraps all error callbacks with augmented traces
packages/client-common/src/index.ts Re-exports getCurrentStackTrace and addStackTrace alongside parseError
packages/client-common/src/error/index.ts Updates error barrel to point to the new error.ts entrypoint
packages/client-common/src/error/error.ts Defines getCurrentStackTrace, addStackTrace, and extends ClickHouseError
Comments suppressed due to low confidence (2)

packages/client-common/src/error/error.ts:37

  • The new utilities getCurrentStackTrace and addStackTrace currently lack dedicated unit tests; adding tests would ensure these functions behave correctly across scenarios.
export function getCurrentStackTrace(): string {

packages/client-common/src/error/error.ts:53

  • [nitpick] addStackTrace is a public API but lacks JSDoc explaining its parameters, return value, and side effects; consider adding a doc comment for clarity.
export function addStackTrace<E extends Error>(err: E, stackTrace: string): E {

socket.setTimeout(this.params.request_timeout, onTimeout)
}

function onTimeout(): void {
const err = addStackTrace(new Error('Timeout error.'), stackTrace)
Copy link
Member

Choose a reason for hiding this comment

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

Error constructor seems to have { cause } for changing the error messages https://nodejs.org/docs/latest-v18.x/api/errors.html#errorcapturestacktracetargetobject-constructoropt

@slvrtrn slvrtrn changed the title Add enhanced stack traces and a few more try-catch blocks [1.11.2] Add enhanced stack traces and a few more try-catch blocks Jun 6, 2025
@slvrtrn
Copy link
Contributor Author

slvrtrn commented Jun 6, 2025

Failed conditions
73.5% Coverage on New Code (required ≥ 80%)

Well, fair enough, let's add more unit tests.

Copy link

sonarqubecloud bot commented Jun 6, 2025

@slvrtrn slvrtrn merged commit f889046 into main Jun 6, 2025
28 checks passed
@slvrtrn slvrtrn deleted the enhanced-stack-traces branch June 6, 2025 16:38
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.

2 participants