{"record":{"id":"9f2e64f39ff006e3","repo":"tursodatabase/turso","slug":"batch-response-is-missing-statement-results","errorCode":null,"errorMessage":"batch response is missing statement results","messagePattern":"batch response is missing statement results","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/session.ts","lineNumber":682,"sourceCode":"      const stepError = stepErrors[firstUserStepIdx + i];\n      if (stepError) {\n        throwStepError(stepError, i);\n      }\n    }\n    if (commitIdx >= 0 && stepErrors[commitIdx]) {\n      throwStepError(stepErrors[commitIdx]);\n    }\n    if (rollbackError) {\n      const error = new DatabaseError(\n        rollbackError.message || 'Batch rollback failed',\n        rollbackError.code,\n      );\n      error.batchResults = results;\n      throw error;\n    }\n\n    if (results.some(result => result === null)) {\n      throw new DatabaseError('batch response is missing statement results');\n    }\n    return results;\n  }\n\n  /** Decode one statement result of a batch response (section 8.4) into\n   * the per-statement result shape returned by `batch()`. */\n  private decodeBatchStepResult(stepResult: ExecuteResult, safeIntegers: boolean, raw: boolean): any {\n    const columns = (stepResult.cols ?? []).map(col => col.name ?? '');\n    const columnTypes = (stepResult.cols ?? []).map(col => col.decltype || '');\n    const rows = (stepResult.rows ?? []).map(row => {\n      const decoded = row.map(value => decodeValue(value, safeIntegers));\n      return raw ? decoded : this.createObjectRow(decoded, columns);\n    });\n    let lastInsertRowid: number | undefined;\n    if (stepResult.last_insert_rowid !== undefined && stepResult.last_insert_rowid !== null) {\n      lastInsertRowid = typeof stepResult.last_insert_rowid === 'number'\n        ? stepResult.last_insert_rowid\n        : parseInt(stepResult.last_insert_rowid, 10);","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/serverless/javascript/src/session.ts#L664-L700","documentation":"After decoding the batch response, batch() maps one result per user statement. If any statement slot is still null (no step result found for it), the batch did not fully execute, and returning partial data silently would hide lost statements — so it throws.","triggerScenarios":"session.batch() where stepResults contains null (or a non-completing marker) for one of the user statements — typically because an earlier step errored and the server skipped subsequent steps, or a step result was missing.","commonSituations":"A mid-batch SQL error aborting the remaining statements, using batch without go:true so statements run sequentially and one failure stops the rest, protocol truncation.","solutions":["Check the thrown error's batchResults property to see which statement failed and why.","Fix the failing statement (syntax, constraint, type error) that aborted the batch.","Use batch(..., 'true') (go: true) if you want independent execution semantics where appropriate.","Wrap each risky statement with SAVEPOINTs or run them in separate batch calls if partial success is acceptable."],"exampleFix":"// before\nawait session.batch([\n  { sql: \"INSERT INTO a ...\" },\n  { sql: \"BROKEN SQL\" },\n  { sql: \"INSERT INTO b ...\" } // never runs -> null result\n]);\n// after\nawait session.batch([\n  { sql: \"INSERT INTO a ...\" },\n  { sql: \"FIXED SQL\" },\n  { sql: \"INSERT INTO b ...\" }\n]);","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try { await session.batch(stmts); } catch (e) { if (e instanceof DatabaseError && e.message === 'batch response is missing statement results') { const failed = e.batchResults?.filter(r => r?.error); /* inspect failing statement and fix SQL */ } else throw e; }","preventionTips":["Validate SQL statements before batching to avoid mid-batch aborts.","Use go:true batch mode when statements should not abort each other.","Inspect e.batchResults on failure to pinpoint the offending statement."],"tags":["serverless","batch","partial-failure"],"backgroundTag":"batch-statement-failed","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"}