{"id":"ba1948e26d791895","repo":"drizzle-team/drizzle-orm","slug":"rollback","errorCode":null,"errorMessage":"Rollback","messagePattern":"Rollback","errorType":"exception","errorClass":"TransactionRollbackError","httpStatus":null,"severity":"warning","filePath":"drizzle-orm/src/gel-core/session.ts","lineNumber":231,"sourceCode":"\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTSchema extends TablesRelationalConfig = Record<string, never>,\n> extends GelDatabase<TQueryResult, TFullSchema, TSchema> {\n\tstatic override readonly [entityKind]: string = 'GelTransaction';\n\n\tconstructor(\n\t\tdialect: GelDialect,\n\t\tsession: GelSession<any, any, any>,\n\t\tprotected schema: {\n\t\t\tfullSchema: Record<string, unknown>;\n\t\t\tschema: TSchema;\n\t\t\ttableNamesMap: Record<string, string>;\n\t\t} | undefined,\n\t) {\n\t\tsuper(dialect, session, schema);\n\t}\n\n\trollback(): never {\n\t\tthrow new TransactionRollbackError();\n\t}\n\n\tabstract override transaction<T>(\n\t\ttransaction: (tx: GelTransaction<TQueryResult, TFullSchema, TSchema>) => Promise<T>,\n\t): Promise<T>;\n}\n\nexport interface GelQueryResultHKT {\n\treadonly $brand: 'GelQueryResultHKT';\n\treadonly row: unknown;\n\treadonly type: unknown;\n}\n\nexport type GelQueryResultKind<TKind extends GelQueryResultHKT, TRow> = (TKind & {\n\treadonly row: TRow;\n})['type'];\n","sourceCodeStart":213,"sourceCodeEnd":248,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/gel-core/session.ts#L213-L248","documentation":"Thrown by GelTransaction.rollback() (line 231) as a TransactionRollbackError. This is the intentional control-flow mechanism Drizzle uses to abort a transaction: calling tx.rollback() throws, which propagates out of the transaction callback and signals the session wrapper to issue a ROLLBACK instead of COMMIT.","triggerScenarios":"User explicitly calls tx.rollback() inside a db.transaction(async (tx) => {...}) callback. Any code path that reaches rollback() will throw; the Gel session catches it and rolls back the underlying transaction.","commonSituations":"Business-rule validation inside a transaction decides the operation should not commit; a nested transaction (savepoint) needs to be aborted; wrapping rollback in custom error handling that accidentally swallows it.","solutions":["Recognize this is expected behavior: do NOT catch and ignore TransactionRollbackError unless you intend to suppress the rollback signal.","If you catch errors around db.transaction, re-throw TransactionRollbackError so the session still rolls back.","Use the return value of db.transaction for success and let rollback() handle abort - don't structure code around the throw.","If you see this leak to a caller unexpectedly, ensure the transaction callback isn't wrapped in a try/catch that swallows it."],"exampleFix":"// before - swallowing rollback breaks the signal\ntry {\n  await db.transaction(async (tx) => {\n    if (!ok) await tx.rollback();\n  });\n} catch (e) { /* swallowed */ }\n\n// after - let it propagate or re-throw\nimport { TransactionRollbackError } from 'drizzle-orm/errors';\ntry {\n  await db.transaction(async (tx) => {\n    if (!ok) tx.rollback();\n  });\n} catch (e) {\n  if (e instanceof TransactionRollbackError) return; // expected\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Decide rollback before entering the transaction\nif (!shouldCommit) return null;\nreturn await db.transaction(async (tx) => { ... });","typeGuard":"import { TransactionRollbackError } from '~/errors.ts';\nfunction isRollback(e: unknown): e is TransactionRollbackError {\n  return e instanceof TransactionRollbackError;\n}","tryCatchPattern":"try {\n  await db.transaction(async (tx) => {\n    if (!ok) tx.rollback();\n    // ...\n  });\n} catch (e) {\n  if (e instanceof TransactionRollbackError) return; // expected\n  throw e;\n}","preventionTips":["Never swallow TransactionRollbackError without re-throwing.","Treat rollback() as control flow, not as an exceptional bug.","Validate business rules before entering the transaction when possible."],"tags":["gel","transaction","rollback","control-flow"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}