cube-js/cube · error

parsed.error

Error message

parsed.error

What it means

A JSON line after the schema containing an `error` key (and no `data`) represents a mid-stream failure (e.g. a post-processing/cast error). cubeSql() surfaces parsed.error instead of pushing a phantom undefined row.

Source

Thrown at packages/cubejs-client-core/src/index.ts:849

        for (const line of data) {
          if (line.trim().length) {
            let parsed: any;
            try {
              parsed = JSON.parse(line);
            } catch (err) {
              // A non-JSON line after a valid schema means a malformed payload — fall
              // back to surfacing the raw response rather than dropping rows silently.
              throw new Error(response.error);
            }

            // The stream can interleave an error chunk after the schema (e.g. a
            // post-processing/cast error surfaced mid-result). Such a line has no
            // `data`, so the previous `JSON.parse(d).data` concat pushed an `undefined`
            // "phantom" row and silently swallowed the failure. Surface it instead —
            // matching how `cubeSqlStream` classifies `error` chunks.
            if (parsed.error) {
              throw new Error(parsed.error);
            }

            if (parsed.data) {
              // Append rows one at a time instead of spreading the whole chunk as
              // call arguments (`rows.push(...parsed.data)`). A large single-chunk
              // result (e.g. 130k+ rows) otherwise exceeds V8's argument-count
              // limit and throws "RangeError: Maximum call stack size exceeded".
              for (let i = 0; i < parsed.data.length; i++) {
                rows.push(parsed.data[i]);
              }
            }
          }
        }

        return {
          schema: parsedSchema.schema,
          data: rows,
          ...(parsedSchema.lastRefreshTime ? { lastRefreshTime: parsedSchema.lastRefreshTime } : {}),

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Fix the underlying server error reported in parsed.error (often a data type/cast problem)
  2. Review cube schema member types vs actual column types
  3. Retry the query to confirm whether it is deterministic
Defensive patterns

Strategy: try-catch

Type guard

function isErrorChunk(parsed) {
  return parsed != null && typeof parsed === 'object' && typeof parsed.error === 'string';
}

Try / catch

try { const res = await client.cubeSql(sql); } catch (e) {
  console.error('Mid-stream CubeSQL error:', e.message);
}

Prevention

When it happens

Trigger: Server emits an error chunk after results started streaming — e.g. type-cast or post-processing failure partway through a result set.

Common situations: Data that fails casting mid-result; server-side errors occurring after initial rows; schema/data mismatch in the cube model.

Related errors


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