{"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":753,"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":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/serverless/javascript/src/session.ts#L735-L771","documentation":"The pipeline response for session.sequence(sql) returned an error-typed result for the multi-statement string. The literal is the fallback when the server error carries no message; the thrown DatabaseError normally includes the server's message and code. Any single failing statement in the semicolon-separated payload fails the whole sequence call.","triggerScenarios":"Calling sequence() with a migration or script string where any one statement is invalid or references a missing object; statements the server refuses to run via the sequence request type; a later statement depending on an earlier one that already failed.","commonSituations":"Feeding a .sql schema dump through sequence(); running migrations that contain a statement for a table added later in the same string; environment drift where an object exists in dev but not prod.","solutions":["Split the script on semicolons and execute statements one by one to find the failing one","Read the thrown error's message and code for the exact server complaint","Fix or reorder the offending statement (e.g. CREATE TABLE before the INSERT that uses it)","For migration files, prefer batch() or per-statement execution with individual error reporting"],"exampleFix":"// before\nawait session.sequence(schemaSql); // one statement fails, whole call fails\n\n// after\nfor (const stmt of schemaSql.split(';').map(s => s.trim()).filter(Boolean)) {\n  await session.execute(stmt);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"import { DatabaseError } from '@tursodatabase/serverless';\n\nfunction isSequenceError(e: unknown): e is DatabaseError {\n  return e instanceof DatabaseError && e.message === 'Sequence execution failed';\n}","tryCatchPattern":"try {\n  await session.sequence(schemaSql);\n} catch (e) {\n  if (e instanceof DatabaseError) {\n    // bisect: run each statement separately to find the failing one\n    for (const stmt of schemaSql.split(';')) await session.execute(stmt);\n  }\n  throw e;\n}","preventionTips":["Prefer per-statement execution (or batch with individual results) for migrations so one bad statement is identifiable","Validate migration scripts against the target schema version before running sequence()","Order statements so dependencies (tables) are created before their users"],"tags":["sql","sequence","migration","typescript"],"backgroundTag":"sql-execution-error","analyzedSha":"c1e59287258d99b309e362a63f48822256e2f65f","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}