{"record":{"id":"60f07f1b08c8129c","repo":"tursodatabase/turso","slug":"sql-execution-failed-60f07f","errorCode":null,"errorMessage":"SQL execution failed","messagePattern":"SQL execution failed","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/statement.ts","lineNumber":298,"sourceCode":"          }\n          break;\n        case 'row':\n          if (entry.row) {\n            const decodedRow = entry.row.map(value => decodeValue(value, this.safeIntegerMode));\n            if (this.presentationMode === 'pluck') {\n              // In pluck mode, yield only the first column value\n              yield decodedRow[0];\n            } else if (this.presentationMode === 'raw') {\n              // In raw mode, yield arrays of values\n              yield decodedRow;\n            } else {\n              yield createExpandedRow(decodedRow, columns);\n            }\n          }\n          break;\n        case 'step_error':\n        case 'error':\n          throw new DatabaseError(entry.error?.message || 'SQL execution failed');\n      }\n    }\n  }\n\n}\n","sourceCodeStart":280,"sourceCodeEnd":304,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/serverless/javascript/src/statement.ts#L280-L304","documentation":"DatabaseError thrown from Statement.iterate() when the cursor stream delivers a step_error or fatal error entry while rows are being yielded from the async generator. Unlike the buffered session path, the error surfaces mid-iteration — some rows may already have been consumed by your for-await loop before the throw; the literal text is the fallback when the entry has no error.message.","triggerScenarios":"for await (const row of stmt.iterate(args)) where the query fails server-side partway through the stream (lock timeout, server restart, kill); message-less error entries producing the fallback wording; errors arriving after the first rows were already yielded and processed.","commonSituations":"Long-running scans interrupted by server restarts or timeouts; processing pipelines that assume all-or-nothing row delivery; iterating while other connections write conflicting data.","solutions":["Read the server message and DatabaseError.code to find the real cause; test the same SQL via all() to check whether it fails deterministically","Handle partial results explicitly — iterate() may yield rows before throwing, so track what was processed","For long queries, page through with LIMIT/keyset pagination instead of one giant stream"],"exampleFix":"// before\nfor await (const row of stmt.iterate()) {\n  await process(row); // error mid-stream aborts with rows already handled\n}\n\n// after\nlet handled = 0;\ntry {\n  for await (const row of stmt.iterate()) { await process(row); handled++; }\n} catch (e) {\n  if (e instanceof Error && e.name === \"DatabaseError\") {\n    await resumeFromCheckpoint(handled); // explicit partial-result policy\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isDatabaseError = (e: unknown): e is Error & { code?: string } =>\n  e instanceof Error && e.name === \"DatabaseError\";","tryCatchPattern":"let handled = 0;\ntry {\n  for await (const row of stmt.iterate(args)) {\n    await process(row);\n    handled++;\n  }\n} catch (e) {\n  if (e instanceof Error && e.name === \"DatabaseError\") {\n    // `handled` rows were already processed — resume from a checkpoint,\n    // rerun idempotently, or surface a partial-result error\n    await resumeFromCheckpoint(handled);\n  } else throw e;\n}","preventionTips":["Make per-row processing idempotent, or checkpoint progress, because iterate() can yield rows before failing","Prefer LIMIT/keyset pagination for very large or long-running result sets","Test iteration paths against server restarts so partial delivery is a handled case, not a crash"],"tags":["sql","iterator","streaming","javascript"],"backgroundTag":"sql-execution-error","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}