{"record":{"id":"f244ce73ab97668a","repo":"tursodatabase/turso","slug":"expected-batch-result-in-pipeline-response-got","errorCode":null,"errorMessage":"expected batch result in pipeline response, got ${first.response?.type}","messagePattern":"expected batch result in pipeline response, got (.+?)","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/session.ts","lineNumber":622,"sourceCode":"      this.autocommit = true;\n      throw e;\n    }\n\n    this.baton = response.baton;\n    if (response.base_url) {\n      this.baseUrl = normalizeUrl(response.base_url);\n    }\n    this.updateAutocommit(response);\n\n    const first = response.results?.[0];\n    if (!first) {\n      throw new DatabaseError('missing batch result in pipeline response');\n    }\n    if (first.type === 'error') {\n      throw new DatabaseError(first.error?.message || 'Batch execution failed', first.error?.code);\n    }\n    if (first.response?.type !== 'batch') {\n      throw new DatabaseError(`expected batch result in pipeline response, got ${first.response?.type}`);\n    }\n    const batchResult = first.response.result as BatchResultData | undefined;\n    const stepResults = batchResult?.step_results;\n    const stepErrors = batchResult?.step_errors;\n    if (\n      !Array.isArray(stepResults) ||\n      !Array.isArray(stepErrors) ||\n      stepResults.length !== steps.length ||\n      stepErrors.length !== steps.length\n    ) {\n      throw new DatabaseError('batch response does not have one result and one error per step');\n    }\n\n    // One result per user statement, in input order; null for statements\n    // that did not complete.\n    const results: Array<any | null> = statements.map((_, i) => {\n      const stepResult = stepResults[firstUserStepIdx + i];\n      return stepResult ? this.decodeBatchStepResult(stepResult, safeIntegers, raw) : null;","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/serverless/javascript/src/session.ts#L604-L640","documentation":"batch() validates that the first pipeline result is of type 'batch'. Getting another type (e.g. 'error', 'close', or 'execute') means the server responded with a pipeline frame the client did not expect, so the result cannot be interpreted as batch step results.","triggerScenarios":"Calling session.batch() where response.results[0].response.type is anything other than 'batch' — protocol version mismatch, server executed the request differently, or response frames got reordered/interleaved by a proxy.","commonSituations":"Client/server version skew after a server upgrade, custom HTTP intermediaries mangling JSON, hitting an endpoint that only supports the older Hrana protocol.","solutions":["Check first.error in surrounding logs for the real server-side failure.","Pin/upgrade client and server to compatible versions.","Bypass proxies by connecting directly to the Turso URL.","Capture and inspect the full pipeline response to identify the unexpected frame type."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"null","typeGuard":"const isBatchResult = (r: any): r is { type: 'batch'; response: { type: 'batch'; result: unknown } } => r?.response?.type === 'batch';","tryCatchPattern":"try { await session.batch(stmts); } catch (e) { if (e instanceof DatabaseError && e.message.startsWith('expected batch result')) { /* inspect server response type, check versions */ } else throw e; }","preventionTips":["Verify protocol compatibility after any server upgrade.","Connect directly to Turso endpoints without intermediaries.","Capture unexpected pipeline frames in logs for bug reports."],"tags":["serverless","protocol","batch"],"backgroundTag":"malformed-server-response","analyzedSha":"c1e59287258d99b309e362a63f48822256e2f65f","analyzedAt":"2026-08-31T11:17:35.598Z","contentChangedAt":"2026-08-31T11:17:35.598Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}