Graceful handling of readonly DB error

This commit is contained in:
Fedor Indutny 2023-03-02 09:59:18 -08:00 committed by GitHub
parent 1e7d658109
commit bd40a7fb98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 27 deletions

View file

@ -65,7 +65,7 @@ import type {
StoredSignedPreKeyType,
} from './Interface';
import Server from './Server';
import { isCorruptionError } from './errors';
import { parseSqliteError, SqliteErrorKind } from './errors';
import { MINUTE } from '../util/durations';
import { getMessageIdForLogging } from '../util/idForLogging';
@ -309,13 +309,18 @@ function makeChannel(fnName: string) {
// Ignoring this error TS2556: Expected 3 arguments, but got 0 or more.
return await serverFn(...args);
} catch (error) {
if (isCorruptionError(error)) {
const sqliteErrorKind = parseSqliteError(error);
if (sqliteErrorKind === SqliteErrorKind.Corrupted) {
log.error(
'Detected sql corruption in renderer process. ' +
`Restarting the application immediately. Error: ${error.message}`
);
ipc?.send('database-error', error.stack);
} else if (sqliteErrorKind === SqliteErrorKind.Readonly) {
log.error(`Detected readonly sql database: ${error.message}`);
ipc?.send('database-readonly');
}
log.error(
`Renderer SQL channel job (${fnName}) error ${error.message}`
);