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

@ -117,7 +117,6 @@ import { load as loadLocale } from './locale';
import type { LoggerType } from '../ts/types/Logging';
import { HourCyclePreference } from '../ts/types/I18N';
import { ScreenShareStatus } from '../ts/types/Calling';
import { DBVersionFromFutureError } from '../ts/sql/migrations';
import type { ParsedSignalRoute } from '../ts/util/signalRoutes';
import { parseSignalRoute } from '../ts/util/signalRoutes';
import * as dns from '../ts/util/dns';
@ -1800,7 +1799,9 @@ const onDatabaseError = async (error: Error) => {
const copyErrorAndQuitButtonIndex = 0;
const SIGNAL_SUPPORT_LINK = 'https://support.signal.org/error';
if (error instanceof DBVersionFromFutureError) {
// Note that this error is thrown by the worker process and thus instanceof
// check won't work.
if (error.name === 'DBVersionFromFutureError') {
// If the DB version is too new, the user likely opened an older version of Signal,
// and they would almost never want to delete their data as a result, so we don't show
// that option

View file

@ -70,7 +70,13 @@ export type WrappedWorkerResponse =
| Readonly<{
type: 'response';
seq: number;
error: string | undefined;
error:
| Readonly<{
name: string;
message: string;
stack: string | undefined;
}>
| undefined;
errorKind: SqliteErrorKind | undefined;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
response: any;
@ -382,7 +388,9 @@ export class MainSQL {
}
if (error) {
const errorObj = new Error(error);
const errorObj = new Error(error.message);
errorObj.stack = error.stack;
errorObj.name = error.name;
this.onError(errorKind ?? SqliteErrorKind.Unknown, errorObj);
pair.reject(errorObj);

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