DrizzleError: Rollback is being rethrown unexpectedly

No matter which error I throw for the rollback - it doesn't work as indented because it bleeds outside the transaction as postgres-js is rethrowing it.
const mute = await db.transaction(async (tx) => {
await tx.rollback();
});
const mute = await db.transaction(async (tx) => {
await tx.rollback();
});
Such simple code results in my top-level error handler being triggered with DrizzleError: Rollback Relevant postgres-js line: https://github.com/porsager/postgres/blob/master/src/index.js#L271
GitHub
postgres/src/index.js at master · porsager/postgres
Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare - porsager/postgres
1 Reply
hkg
hkgOP8mo ago
This is what I'm getting from my top-level handler.
top level error handler 1 | import { entityKind } from "./entity.js";
2 | class DrizzleError extends Error {
3 | static [entityKind] = "DrizzleError";
4 | constructor({ message, cause }) {
5 | super(message);
^
DrizzleError: Rollback
at new DrizzleError (/workspaces/hashira/packages/db/node_modules/drizzle-orm/errors.js:5:5)
at new TransactionRollbackError (/workspaces/hashira/packages/db/node_modules/drizzle-orm/errors.js:13:5)
at rollback (/workspaces/hashira/packages/db/node_modules/drizzle-orm/pg-core/session.js:55:11)
at /workspaces/hashira/apps/bot/src/moderation/mutes.ts:156:23
at /workspaces/hashira/apps/bot/src/moderation/mutes.ts:155:56
at /workspaces/hashira/packages/db/node_modules/drizzle-orm/postgres-js/session.js:97:37
at /workspaces/hashira/node_modules/postgres/src/index.js:260:21
at new Promise (:1:21)
at /workspaces/hashira/node_modules/postgres/src/index.js:259:24
at scope (/workspaces/hashira/node_modules/postgres/src/index.js:250:29)
at /workspaces/hashira/node_modules/postgres/src/index.js:243:9
top level error handler 1 | import { entityKind } from "./entity.js";
2 | class DrizzleError extends Error {
3 | static [entityKind] = "DrizzleError";
4 | constructor({ message, cause }) {
5 | super(message);
^
DrizzleError: Rollback
at new DrizzleError (/workspaces/hashira/packages/db/node_modules/drizzle-orm/errors.js:5:5)
at new TransactionRollbackError (/workspaces/hashira/packages/db/node_modules/drizzle-orm/errors.js:13:5)
at rollback (/workspaces/hashira/packages/db/node_modules/drizzle-orm/pg-core/session.js:55:11)
at /workspaces/hashira/apps/bot/src/moderation/mutes.ts:156:23
at /workspaces/hashira/apps/bot/src/moderation/mutes.ts:155:56
at /workspaces/hashira/packages/db/node_modules/drizzle-orm/postgres-js/session.js:97:37
at /workspaces/hashira/node_modules/postgres/src/index.js:260:21
at new Promise (:1:21)
at /workspaces/hashira/node_modules/postgres/src/index.js:259:24
at scope (/workspaces/hashira/node_modules/postgres/src/index.js:250:29)
at /workspaces/hashira/node_modules/postgres/src/index.js:243:9
Hm, wrapping transaction inside of try/catch makes it work, but its dirty Should I migrate this to github issues?
Want results from more Discord servers?
Add your server