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

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