{"record":{"id":"1dcbe18cb3a7dcbb","repo":"tursodatabase/turso","slug":"sequence-execution-failed","errorCode":null,"errorMessage":"Sequence execution failed","messagePattern":"Sequence execution failed","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"error","filePath":"serverless/javascript/src/session.ts","lineNumber":670,"sourceCode":"    try {\n      seqResponse = await executePipeline(this.httpContext(queryOptions), request, this.createAbortSignal(queryOptions));\n    } catch (e) {\n      this.baton = null;\n      this.autocommit = true;\n      throw e;\n    }\n\n    this.baton = seqResponse.baton;\n    if (seqResponse.base_url) {\n      this.baseUrl = normalizeUrl(seqResponse.base_url);\n    }\n    this.updateAutocommit(seqResponse);\n\n    // Check for errors in the response\n    if (seqResponse.results && seqResponse.results[0]) {\n      const result = seqResponse.results[0];\n      if (result.type === \"error\") {\n        throw new DatabaseError(result.error?.message || 'Sequence execution failed', result.error?.code);\n      }\n    }\n  }\n\n  /**\n   * Close the session.\n   *\n   * This sends a close request to the server to properly clean up the stream\n   * before resetting the local state.\n   */\n  async close(): Promise<void> {\n    // Only send close request if we have an active baton\n    if (this.baton) {\n      try {\n        const request: PipelineRequest = {\n          baton: this.baton,\n          requests: [{\n            type: \"close\"","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/serverless/javascript/src/session.ts#L652-L688","documentation":"DatabaseError thrown when the server marks the first result of a sequence request as an error with no message — the literal 'Sequence execution failed' is the fallback; the server's own message is used when present. Sequences carry multi-statement SQL strings and back Connection.exec() and Transaction.exec(), so any failing statement in the script fails the whole call.","triggerScenarios":"db.exec('CREATE TABLE ...; INSERT ...') where any statement in the script has a syntax error, references a missing object, or violates a constraint; Transaction.exec of migration scripts inside transactionAsync; dynamically joined SQL with a trailing malformed fragment.","commonSituations":"Applying schema migrations containing dialect-specific SQL the server rejects; seed scripts with constraint-violating rows; semicolon-joined statements built at runtime where one optional fragment is empty or malformed.","solutions":["Split the script and run statements individually to isolate which one fails, then fix it per the server message","Verify the script against the CLI before shipping (scripts/diff.sh or the shell)","Wrap migrations in transactionAsync + tx.exec so a failed script rolls back instead of leaving partial DDL applied"],"exampleFix":"// before\nawait db.exec(readFileSync(\"schema.sql\", \"utf8\")); // one bad statement fails the whole sequence\n\n// after\nfor (const stmt of readFileSync(\"schema.sql\", \"utf8\")\n  .split(\";\").map((s) => s.trim()).filter(Boolean)) {\n  await db.exec(stmt); // isolate and fix the failing statement\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isDatabaseError = (e: unknown): e is Error & { code?: string } =>\n  e instanceof Error && e.name === \"DatabaseError\";","tryCatchPattern":"try {\n  await db.exec(script);\n} catch (e) {\n  if (e instanceof Error && e.name === \"DatabaseError\") {\n    // split and run one statement at a time to identify the failing one\n    for (const stmt of script.split(\";\").map((s) => s.trim()).filter(Boolean)) {\n      await db.exec(stmt); // throws on the exact bad statement\n    }\n  } else throw e;\n}","preventionTips":["Dry-run migration scripts against a copy of production before applying","Run migrations inside transactionAsync + tx.exec so a failed script rolls back cleanly","Lint dynamically built SQL to catch empty or malformed fragments before exec()"],"tags":["sql","exec","multi-statement","javascript"],"backgroundTag":"sql-execution-error","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}