cube-js/cube · error

Stream init error

Error message

Stream init error

What it means

getFileStream prepares a temp file and writer for streaming table data. If the async initialization did not produce a currentFileStream (e.g. the temp-file creation promise failed silently or pipeline setup threw before assignment), the driver throws 'Stream init error'.

Source

Thrown at packages/cubejs-cubestore-driver/src/CubeStoreDriver.ts:403

              const fileName = `${table}-${fileCounter++}.csv.gz`;
              filePromises.push(fetch(`${baseUrl.replace(/^ws/, 'http')}/upload-temp-file?name=${fileName}`, {
                method: 'POST',
                body: createReadStream(tempFile),
              }).then(async res => {
                if (res.status !== 200) {
                  const error = await res.json();
                  throw new Error(`Error during upload of ${fileName} create table: ${createTableSqlWithoutLocation}: ${error.error}`);
                }
                return fileName;
              }));

              resolve(null);
            });
            currentFileStream = { stream: writer, tempFile };
          }));
        }
        if (!currentFileStream) {
          throw new Error('Stream init error');
        }
        return currentFileStream;
      };

      let rowCount = 0;

      const endStream = (chunk, encoding, callback) => {
        const { stream } = getFileStream();
        currentFileStream = null;
        rowCount = 0;
        if (chunk) {
          stream.end(chunk, encoding, callback);
        } else {
          stream.end(callback);
        }
      };

      const { batchingRowSplitCount } = this.config;

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Check temp directory writability and free disk space (TMPDIR / /tmp).
  2. Inspect earlier async errors swallowed by the pipeline promise (add logging).
  3. Verify process file-descriptor limits.
  4. Retry the pre-aggregation build after fixing the environment.
Defensive patterns

Strategy: validation

Validate before calling

import { accessSync, constants } from 'fs';
const tmpDir = process.env.TMPDIR || '/tmp';
accessSync(tmpDir, constants.W_OK); // throws early if temp dir is not writable

Try / catch

try {
  await driver.uploadTable(table, columns, tableData);
} catch (e) {
  if (e.message === 'Stream init error') {
    console.error('Temp file/stream init failed: check TMPDIR writability and disk space');
  }
  throw e;
}

Prevention

When it happens

Trigger: Temp file creation (tmpFile creation) or writer setup inside the promise chain rejects/resolves without setting currentFileStream, so the check `if (!currentFileStream)` fires.

Common situations: No writable temp directory (TMPDIR unwritable/full); permission errors creating temp files; OS-level file limits; Cube Store connection established after data already flowed.

Related errors


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