Run integrity checks on database corruption

This commit is contained in:
Fedor Indutny 2023-10-11 01:19:11 +02:00 committed by GitHub
parent 064659657f
commit f5c18cfb51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 14 deletions

View file

@ -11,6 +11,7 @@ import type {
WrappedWorkerLogEntry,
} from './main';
import db from './Server';
import { SqliteErrorKind, parseSqliteError } from './errors';
if (!parentPort) {
throw new Error('Must run as a worker thread');
@ -20,10 +21,22 @@ const port = parentPort;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function respond(seq: number, error: Error | undefined, response?: any) {
let errorKind: SqliteErrorKind | undefined;
let errorString: string | undefined;
if (error !== undefined) {
errorKind = parseSqliteError(error);
errorString = Errors.toLogFormat(error);
if (errorKind === SqliteErrorKind.Corrupted) {
db.runCorruptionChecks();
}
}
const wrappedResponse: WrappedWorkerResponse = {
type: 'response',
seq,
error: error === undefined ? undefined : Errors.toLogFormat(error),
error: errorString,
errorKind,
response,
};
port.postMessage(wrappedResponse);