Better reporting for DB corruption errors

This commit is contained in:
Fedor Indutny 2021-10-21 13:13:33 -07:00 committed by GitHub
parent 092c2fd0d7
commit 1b1ed2cd05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 5 deletions

View File

@ -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",

View File

@ -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;
}
}

View File

@ -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}`

View File

@ -550,6 +550,8 @@ export type ServerInterface = DataInterface & {
// Server-only
getCorruptionLog: () => string;
initialize: (options: {
configDir: string;
key: string;

View File

@ -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<string>();
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,

View File

@ -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);

View File

@ -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"