{"record":{"id":"ec5608e826012a8d","repo":"tursodatabase/turso","slug":"batch-response-does-not-have-one-result-and-one-er","errorCode":null,"errorMessage":"batch response does not have one result and one error per step","messagePattern":"batch response does not have one result and one error per step","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/session.ts","lineNumber":633,"sourceCode":"    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;\n    });\n\n    // Surface the failing step: BEGIN first, then the user statements\n    // (with their index), then COMMIT.\n    const rollbackError = rollbackIdx >= 0 ? stepErrors[rollbackIdx] : null;\n    const throwStepError = (error: { message?: string; code?: string } | null, batchIndex?: number): never => {\n      const e = new DatabaseError(error?.message || 'Batch execution failed', error?.code);\n      if (batchIndex !== undefined) {\n        e.batchIndex = batchIndex;\n      }\n      e.batchResults = results;","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/serverless/javascript/src/session.ts#L615-L651","documentation":"The batch protocol guarantees one result slot and one error slot per submitted step. When the returned step_results/step_errors arrays are missing, not arrays, or differ in length from the number of steps, the client cannot map results back to statements and throws.","triggerScenarios":"session.batch() with N steps where the server's BatchResultData has step_results/step_errors arrays of length != N, or non-array values — server bug, truncated response, or partial pipeline execution.","commonSituations":"Server under load returning partial pipeline data, network middleboxes truncating large batch responses, protocol drift between client and server versions.","solutions":["Retry the batch to rule out a transient truncation.","Split very large batches into smaller ones to reduce response size.","Verify client and server versions match.","Inspect the raw response JSON to confirm what the server sent before filing a bug."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":null,"tryCatchPattern":"try { await session.batch(stmts); } catch (e) { if (e instanceof DatabaseError && e.message.includes('one result and one error per step')) { /* retry with backoff; reduce batch size if large */ } else throw e; }","preventionTips":["Keep batches modest in size to avoid large/truncated responses.","Match client/server protocol versions.","Retry idempotent batches on protocol anomalies."],"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-14T00:17:10.932Z"}