Show error toast on database errors
This commit is contained in:
parent
c38e871ca9
commit
60f55f1749
7 changed files with 76 additions and 15 deletions
|
@ -92,6 +92,7 @@ type ResponseEntry<T> = {
|
|||
type KnownErrorResolverType = Readonly<{
|
||||
kind: SqliteErrorKind;
|
||||
resolve: (err: Error) => void;
|
||||
once?: boolean;
|
||||
}>;
|
||||
|
||||
type CreateWorkerResultType = Readonly<{
|
||||
|
@ -210,16 +211,31 @@ export class MainSQL {
|
|||
|
||||
public whenCorrupted(): Promise<Error> {
|
||||
const { promise, resolve } = explodePromise<Error>();
|
||||
this.#errorResolvers.push({ kind: SqliteErrorKind.Corrupted, resolve });
|
||||
this.#errorResolvers.push({
|
||||
kind: SqliteErrorKind.Corrupted,
|
||||
resolve,
|
||||
once: true,
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
public whenReadonly(): Promise<Error> {
|
||||
const { promise, resolve } = explodePromise<Error>();
|
||||
this.#errorResolvers.push({ kind: SqliteErrorKind.Readonly, resolve });
|
||||
this.#errorResolvers.push({
|
||||
kind: SqliteErrorKind.Readonly,
|
||||
resolve,
|
||||
once: true,
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
public onUnknownSqlError(callback: (error: Error) => void): void {
|
||||
this.#errorResolvers.push({
|
||||
kind: SqliteErrorKind.Unknown,
|
||||
resolve: callback,
|
||||
});
|
||||
}
|
||||
|
||||
public async close(): Promise<void> {
|
||||
if (this.#onReady) {
|
||||
try {
|
||||
|
@ -375,15 +391,13 @@ export class MainSQL {
|
|||
}
|
||||
|
||||
#onError(errorKind: SqliteErrorKind, error: Error): void {
|
||||
if (errorKind === SqliteErrorKind.Unknown) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resolvers = new Array<(error: Error) => void>();
|
||||
this.#errorResolvers = this.#errorResolvers.filter(entry => {
|
||||
if (entry.kind === errorKind) {
|
||||
resolvers.push(entry.resolve);
|
||||
return false;
|
||||
if (entry.once) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue