{"record":{"id":"9e088538542da68a","repo":"cube-js/cube","slug":"response-error","errorCode":null,"errorMessage":"response.error","messagePattern":"response\\.error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-client-core/src/index.ts","lineNumber":827,"sourceCode":"\n        // Check if this is a timeout or abort error from transport\n        if (response.error === 'timeout') {\n          const timeoutMs = options?.timeout || 5 * 60 * 1000;\n          throw new Error(`CubeSQL query timed out after ${timeoutMs}ms`);\n        }\n\n        if (response.error === 'aborted') {\n          throw new Error('CubeSQL query was aborted');\n        }\n\n        const [schema, ...data] = response.error.split('\\n');\n\n        let parsedSchema: any;\n        try {\n          parsedSchema = JSON.parse(schema);\n        } catch (err) {\n          // Schema line isn't valid JSON — the whole `error` payload is a real error.\n          throw new Error(response.error);\n        }\n\n        const rows: any[] = [];\n\n        for (const line of data) {\n          if (line.trim().length) {\n            let parsed: any;\n            try {\n              parsed = JSON.parse(line);\n            } catch (err) {\n              // A non-JSON line after a valid schema means a malformed payload — fall\n              // back to surfacing the raw response rather than dropping rows silently.\n              throw new Error(response.error);\n            }\n\n            // The stream can interleave an error chunk after the schema (e.g. a\n            // post-processing/cast error surfaced mid-result). Such a line has no\n            // `data`, so the previous `JSON.parse(d).data` concat pushed an `undefined`","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-client-core/src/index.ts#L809-L845","documentation":"CubeSQL responses arrive as a newline-delimited payload with a JSON schema line first. If the first line is not valid JSON, the code concludes the entire `error` string is a plain-text server error and rethrows it verbatim.","triggerScenarios":"cubeSql() receiving an error payload whose first line isn't JSON — e.g. a raw stack trace, HTML error page, or plain message from the CubeSQL server.","commonSituations":"SQL syntax errors surfaced as plain text; server behind a proxy returning HTML 502 pages; CubeSQL backend version emitting a different format.","solutions":["Read the thrown message — it contains the raw server error; fix the underlying SQL/server issue","Verify you are hitting the cubesql endpoint of a Cube deployment that supports the SQL API","Check for proxies returning HTML error pages instead of JSONL"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify the deployment supports the SQL API and no proxy rewrites the endpoint\nconst health = await fetch(`${apiUrl.replace(/\\/$/, '')}/load`, { headers: { authorization: token } });\nif (!health.ok) throw new Error('Cube API endpoint unreachable; fix before cubeSql calls');","typeGuard":null,"tryCatchPattern":"try { const res = await client.cubeSql(sql); } catch (e) {\n  // raw server error is rethrown verbatim — inspect and fix server/SQL issue\n  console.error('CubeSQL server error:', e.message);\n}","preventionTips":["Validate SQL against the cube schema before sending","Ensure proxies return JSONL, not HTML error pages","Pin compatible Cube server and client versions"],"tags":["cubesql","parsing","server-error"],"backgroundTag":"invalid-response-format","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}