{"record":{"id":"c8fb837d350abb6d","repo":"cube-js/cube","slug":"stream-init-error","errorCode":null,"errorMessage":"Stream init error","messagePattern":"Stream init error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-cubestore-driver/src/CubeStoreDriver.ts","lineNumber":403,"sourceCode":"              const fileName = `${table}-${fileCounter++}.csv.gz`;\n              filePromises.push(fetch(`${baseUrl.replace(/^ws/, 'http')}/upload-temp-file?name=${fileName}`, {\n                method: 'POST',\n                body: createReadStream(tempFile),\n              }).then(async res => {\n                if (res.status !== 200) {\n                  const error = await res.json();\n                  throw new Error(`Error during upload of ${fileName} create table: ${createTableSqlWithoutLocation}: ${error.error}`);\n                }\n                return fileName;\n              }));\n\n              resolve(null);\n            });\n            currentFileStream = { stream: writer, tempFile };\n          }));\n        }\n        if (!currentFileStream) {\n          throw new Error('Stream init error');\n        }\n        return currentFileStream;\n      };\n\n      let rowCount = 0;\n\n      const endStream = (chunk, encoding, callback) => {\n        const { stream } = getFileStream();\n        currentFileStream = null;\n        rowCount = 0;\n        if (chunk) {\n          stream.end(chunk, encoding, callback);\n        } else {\n          stream.end(callback);\n        }\n      };\n\n      const { batchingRowSplitCount } = this.config;","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-cubestore-driver/src/CubeStoreDriver.ts#L385-L421","documentation":"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'.","triggerScenarios":"Temp file creation (tmpFile creation) or writer setup inside the promise chain rejects/resolves without setting currentFileStream, so the check `if (!currentFileStream)` fires.","commonSituations":"No writable temp directory (TMPDIR unwritable/full); permission errors creating temp files; OS-level file limits; Cube Store connection established after data already flowed.","solutions":["Check temp directory writability and free disk space (TMPDIR / /tmp).","Inspect earlier async errors swallowed by the pipeline promise (add logging).","Verify process file-descriptor limits.","Retry the pre-aggregation build after fixing the environment."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { accessSync, constants } from 'fs';\nconst tmpDir = process.env.TMPDIR || '/tmp';\naccessSync(tmpDir, constants.W_OK); // throws early if temp dir is not writable","typeGuard":null,"tryCatchPattern":"try {\n  await driver.uploadTable(table, columns, tableData);\n} catch (e) {\n  if (e.message === 'Stream init error') {\n    console.error('Temp file/stream init failed: check TMPDIR writability and disk space');\n  }\n  throw e;\n}","preventionTips":["Ensure the build process has a writable temp directory with free space.","Avoid low file-descriptor limits (ulimit -n) in build containers.","Clean stale temp files regularly on build hosts.","Check for swallowed errors in stream setup by enabling driver debug logs."],"tags":["cubestore","streaming","filesystem"],"backgroundTag":"temp-file-init-failed","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}