{"record":{"id":"c6a71ad5411e25da","repo":"cube-js/cube","slug":"stream-query-failed-e-query-id-queryid","errorCode":null,"errorMessage":"Stream query failed: ${e}; query id: ${queryId}","messagePattern":"Stream query failed: (.+?); query id: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts","lineNumber":451,"sourceCode":"      const rowStream = Readable.from(dataRowsIter);\n\n      return {\n        rowStream,\n        types: names.map((name, idx) => {\n          const type = types[idx];\n          return {\n            name,\n            type: this.toGenericType(type),\n          };\n        }),\n        release: async () => {\n          await client.close();\n        }\n      };\n    } catch (e) {\n      await client.close();\n      // TODO replace string formatting with proper cause\n      throw new Error(`Stream query failed: ${e}; query id: ${queryId}`);\n    }\n  }\n\n  public async downloadQueryResults(\n    query: string,\n    values: unknown[],\n    options: DownloadQueryResultsOptions\n  ): Promise<DownloadQueryResultsResult> {\n    if ((options ?? {}).streamImport) {\n      return this.stream(query, values, options);\n    }\n\n    const response = await this.queryResponse(query, values);\n\n    return {\n      rows: this.normaliseResponse(response),\n      types: (response.meta ?? []).map((field) => ({\n        name: field.name,","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts#L433-L469","documentation":"Generic wrapper for any exception thrown while setting up or consuming the streaming query in stream(). The original error `e` is string-interpolated into the message (there is no `cause` preserved), along with the ClickHouse query id, so the root cause must be recovered from the interpolated text.","triggerScenarios":"Any failure inside the try block of stream() called via downloadQueryResults(): client creation or query execution failures, connection/auth errors, or errors thrown by the row iteration (including errors 160/161 which get re-wrapped by this handler).","commonSituations":"Wrong ClickHouse credentials/host/port; network unreachable; query syntax errors; context timeouts on large streaming queries; underlying stream-end errors wrapped by this message.","solutions":["Parse the interpolated `${e}` text for the root cause (connection refused, auth failed, syntax error, etc.) and fix that underlying issue first","Use the query id in the message to look up the query in ClickHouse system.query_log for the server-side error","Verify CLICKHOUSECubeJS config: url, port, user, password, database are correct and reachable","Increase query/execution timeouts for large streaming result sets","Upgrade the driver — newer versions replace string formatting with proper error causes"],"exampleFix":"// before\nthrow new Error(`Stream query failed: ${e}; query id: ${queryId}`);\n// after (in driver)\nthrow new Error(`Stream query failed: ${e}; query id: ${queryId}`, { cause: e });","handlingStrategy":"try-catch","validationCode":"// Verify connectivity/credentials up front\nawait driver.query('SELECT 1', []);","typeGuard":"null","tryCatchPattern":"try { return await driver.downloadQueryResults(q, v); }\ncatch (e) {\n  const m = String(e.message);\n  const queryId = m.match(/query id: ([^\\s]+)/)?.[1];\n  log.error('stream query failed', { queryId, cause: m });\n  throw e;\n}","preventionTips":["Extract and log the query id for ClickHouse system.query_log lookups","Validate ClickHouse credentials and connectivity at startup","Set realistic timeouts for large streaming queries"],"tags":["clickhouse","network","error-wrapping","streaming"],"backgroundTag":"query-execution-failed","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}