Better database errors in worker thread

This commit is contained in:
Fedor Indutny 2024-08-13 13:42:20 -07:00 committed by GitHub
parent 2cbc1a82b2
commit 6143888f6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 8 deletions

View file

@ -4,7 +4,6 @@
import { parentPort } from 'worker_threads';
import type { LoggerType } from '../types/Logging';
import * as Errors from '../types/errors';
import type {
WrappedWorkerRequest,
WrappedWorkerResponse,
@ -23,10 +22,8 @@ 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 != null) {
DataWriter.runCorruptionChecks(db);
@ -36,7 +33,14 @@ function respond(seq: number, error: Error | undefined, response?: any) {
const wrappedResponse: WrappedWorkerResponse = {
type: 'response',
seq,
error: errorString,
error:
error == null
? undefined
: {
name: error.name,
message: error.message,
stack: error.stack,
},
errorKind,
response,
};