cube-js/cube · error

Stream query failed: ${e}; query id: ${queryId}

Error message

Stream query failed: ${e}; query id: ${queryId}

What it means

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.

Source

Thrown at packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts:451

      const rowStream = Readable.from(dataRowsIter);

      return {
        rowStream,
        types: names.map((name, idx) => {
          const type = types[idx];
          return {
            name,
            type: this.toGenericType(type),
          };
        }),
        release: async () => {
          await client.close();
        }
      };
    } catch (e) {
      await client.close();
      // TODO replace string formatting with proper cause
      throw new Error(`Stream query failed: ${e}; query id: ${queryId}`);
    }
  }

  public async downloadQueryResults(
    query: string,
    values: unknown[],
    options: DownloadQueryResultsOptions
  ): Promise<DownloadQueryResultsResult> {
    if ((options ?? {}).streamImport) {
      return this.stream(query, values, options);
    }

    const response = await this.queryResponse(query, values);

    return {
      rows: this.normaliseResponse(response),
      types: (response.meta ?? []).map((field) => ({
        name: field.name,

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Parse the interpolated `${e}` text for the root cause (connection refused, auth failed, syntax error, etc.) and fix that underlying issue first
  2. Use the query id in the message to look up the query in ClickHouse system.query_log for the server-side error
  3. Verify CLICKHOUSECubeJS config: url, port, user, password, database are correct and reachable
  4. Increase query/execution timeouts for large streaming result sets
  5. Upgrade the driver — newer versions replace string formatting with proper error causes

Example fix

// before
throw new Error(`Stream query failed: ${e}; query id: ${queryId}`);
// after (in driver)
throw new Error(`Stream query failed: ${e}; query id: ${queryId}`, { cause: e });
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify connectivity/credentials up front
await driver.query('SELECT 1', []);

Type guard

null

Try / catch

try { return await driver.downloadQueryResults(q, v); }
catch (e) {
  const m = String(e.message);
  const queryId = m.match(/query id: ([^\s]+)/)?.[1];
  log.error('stream query failed', { queryId, cause: m });
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: Wrong ClickHouse credentials/host/port; network unreachable; query syntax errors; context timeouts on large streaming queries; underlying stream-end errors wrapped by this message.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/c6a71ad5411e25da. Report an issue: GitHub.