{"record":{"id":"a800361a8ab20076","repo":"earendil-works/pi","slug":"sqlite-transaction-callbacks-must-be-synchronous","errorCode":null,"errorMessage":"SQLite transaction callbacks must be synchronous","messagePattern":"SQLite transaction callbacks must be synchronous","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/session-backends/sqlite-node/src/index.ts","lineNumber":82,"sourceCode":"\n\tconstructor(db: DatabaseSync) {\n\t\tthis.db = db;\n\t}\n\n\texec(sql: string): void {\n\t\tthis.db.exec(sql);\n\t}\n\n\tprepare(sql: string): SqliteStatement {\n\t\treturn new NodeSqliteStatement(this.db.prepare(sql));\n\t}\n\n\ttransaction<T>(fn: () => T): T {\n\t\tsql`BEGIN IMMEDIATE`.exec(this);\n\t\ttry {\n\t\t\tconst result = fn();\n\t\t\tif (isAsyncResult(result)) {\n\t\t\t\tthrow new TypeError(\"SQLite transaction callbacks must be synchronous\");\n\t\t\t}\n\t\t\tsql`COMMIT`.exec(this);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tsql`ROLLBACK`.exec(this);\n\t\t\t} catch {\n\t\t\t\t// Ignore rollback errors to rethrow original error.\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tclose(): void {\n\t\tthis.db.close();\n\t}\n}\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/earendil-works/pi/blob/4af9d21d3b4d664e4a29fcabfec85171077248e3/packages/session-backends/sqlite-node/src/index.ts#L64-L100","documentation":"Guard inside the synchronous SQLite transaction wrapper: the callback passed to transaction() returned a thenable (isAsyncResult detected a Promise/async result). The wrapper has already executed BEGIN IMMEDIATE and cannot hold the write transaction across an await, so it aborts the COMMIT path and rolls back rather than corrupting transactional state.","triggerScenarios":"Thrown at packages/session-backends/sqlite-node/src/index.ts:82 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the transaction callback synchronous; async callbacks are not supported inside SQLite transactions."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4af9d21d3b4d664e4a29fcabfec85171077248e3","analyzedAt":"2026-08-24T13:07:14.692Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}