diff --git a/package.json b/package.json index e715a11d9..839562c43 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "array-move": "2.1.0", "axe-core": "4.1.4", "backbone": "1.4.0", - "better-sqlite3": "https://github.com/signalapp/better-sqlite3#2fa02d2484e9f9a10df5ac7ea4617fb2dff30006", + "better-sqlite3": "https://github.com/signalapp/better-sqlite3#32828e03be0489572ab334239c5768c86697989f", "bezier-easing": "2.1.0", "blob-util": "2.0.2", "blueimp-load-image": "5.14.0", diff --git a/patches/@types+better-sqlite3+7.4.0.patch b/patches/@types+better-sqlite3+7.4.0.patch new file mode 100644 index 000000000..a90fad55e --- /dev/null +++ b/patches/@types+better-sqlite3+7.4.0.patch @@ -0,0 +1,12 @@ +diff --git a/node_modules/@types/better-sqlite3/index.d.ts b/node_modules/@types/better-sqlite3/index.d.ts +index d6e4309..5948fd0 100755 +--- a/node_modules/@types/better-sqlite3/index.d.ts ++++ b/node_modules/@types/better-sqlite3/index.d.ts +@@ -84,6 +84,7 @@ declare namespace BetterSqlite3 { + prototype: Database; + + SqliteError: typeof SqliteError; ++ setCorruptionLogger(fn: (message: string) => void): void; + } + } + diff --git a/ts/sql/Client.ts b/ts/sql/Client.ts index 6411a43d0..a0227ab82 100644 --- a/ts/sql/Client.ts +++ b/ts/sql/Client.ts @@ -573,7 +573,10 @@ function makeChannel(fnName: string) { 'Detected sql corruption in renderer process. ' + `Restarting the application immediately. Error: ${error.message}` ); - ipc?.send('database-error', error.stack); + ipc?.send( + 'database-error', + `${error.stack}\n${Server.getCorruptionLog()}` + ); } log.error( `Renderer SQL channel job (${fnName}) error ${error.message}` diff --git a/ts/sql/Interface.ts b/ts/sql/Interface.ts index 3cc29e26a..a39d8592c 100644 --- a/ts/sql/Interface.ts +++ b/ts/sql/Interface.ts @@ -550,6 +550,8 @@ export type ServerInterface = DataInterface & { // Server-only + getCorruptionLog: () => string; + initialize: (options: { configDir: string; key: string; diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index ee66e8088..06842fe76 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -276,6 +276,7 @@ const dataInterface: ServerInterface = { // Server-only + getCorruptionLog, initialize, initializeRenderer, @@ -2695,6 +2696,19 @@ let globalInstanceRenderer: Database | undefined; let databaseFilePath: string | undefined; let indexedDBPath: string | undefined; +let corruptionLog = new Array(); + +SQL.setCorruptionLogger(line => { + logger.error(`SQL corruption: ${line}`); + corruptionLog.push(line); +}); + +function getCorruptionLog(): string { + const result = corruptionLog.join('\n'); + corruptionLog = []; + return result; +} + async function initialize({ configDir, key, diff --git a/ts/sql/mainWorker.ts b/ts/sql/mainWorker.ts index 838f93fcc..04f1a151c 100644 --- a/ts/sql/mainWorker.ts +++ b/ts/sql/mainWorker.ts @@ -19,10 +19,17 @@ const port = parentPort; // eslint-disable-next-line @typescript-eslint/no-explicit-any function respond(seq: number, error: Error | undefined, response?: any) { + const corruptionLog = db.getCorruptionLog(); + + const errorMessage = [ + ...(error ? [error.stack] : []), + ...(corruptionLog ? [corruptionLog] : []), + ].join('\n'); + const wrappedResponse: WrappedWorkerResponse = { type: 'response', seq, - error: error ? error.stack : undefined, + error: errorMessage, response, }; port.postMessage(wrappedResponse); diff --git a/yarn.lock b/yarn.lock index 35806d179..fd88cb223 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4794,9 +4794,9 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" -"better-sqlite3@https://github.com/signalapp/better-sqlite3#2fa02d2484e9f9a10df5ac7ea4617fb2dff30006": +"better-sqlite3@https://github.com/signalapp/better-sqlite3#32828e03be0489572ab334239c5768c86697989f": version "7.1.4" - resolved "https://github.com/signalapp/better-sqlite3#2fa02d2484e9f9a10df5ac7ea4617fb2dff30006" + resolved "https://github.com/signalapp/better-sqlite3#32828e03be0489572ab334239c5768c86697989f" dependencies: bindings "^1.5.0" tar "^6.1.0"