From 87aa284a669e0dd12844cd8a1624f4e579d72381 Mon Sep 17 00:00:00 2001 From: Grant Forrest Date: Fri, 29 Nov 2024 21:35:36 -0500 Subject: [PATCH] ignore illegal abort invocation --- .changeset/many-roses-dance.md | 6 ++++++ packages/persistence-sqlite/src/SqliteService.ts | 13 ++++++++++--- packages/store/src/persistence/idb/IdbService.ts | 12 ++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 .changeset/many-roses-dance.md diff --git a/.changeset/many-roses-dance.md b/.changeset/many-roses-dance.md new file mode 100644 index 00000000..27673ced --- /dev/null +++ b/.changeset/many-roses-dance.md @@ -0,0 +1,6 @@ +--- +'@verdant-web/persistence-sqlite': patch +'@verdant-web/store': patch +--- + +Ignore illegal invocation error from abort controller diff --git a/packages/persistence-sqlite/src/SqliteService.ts b/packages/persistence-sqlite/src/SqliteService.ts index 7bcbf677..99128bcf 100644 --- a/packages/persistence-sqlite/src/SqliteService.ts +++ b/packages/persistence-sqlite/src/SqliteService.ts @@ -1,7 +1,6 @@ -import { Database, Tables } from './kysely.js'; import { QueryMode } from '@verdant-web/store'; -import { Transaction } from './kysely.js'; import { Disposable } from '@verdant-web/store/internal'; +import { Database, Tables, Transaction } from './kysely.js'; export class SqliteService extends Disposable { private globalAbortController = new AbortController(); @@ -9,7 +8,15 @@ export class SqliteService extends Disposable { constructor(protected db: Database) { super(); this.addDispose(() => { - this.globalAbortController.abort(); + try { + this.globalAbortController.abort(); + } catch (err) { + if (err instanceof Error && err.message.includes('invocation')) { + // Ignore + return; + } + console.error('Error aborting global controller', err); + } }); } diff --git a/packages/store/src/persistence/idb/IdbService.ts b/packages/store/src/persistence/idb/IdbService.ts index 97d3f7a2..e1c3a24b 100644 --- a/packages/store/src/persistence/idb/IdbService.ts +++ b/packages/store/src/persistence/idb/IdbService.ts @@ -1,10 +1,10 @@ import { Context } from '../../context/context.js'; +import { Disposable } from '../../utils/Disposable.js'; import { createAbortableTransaction, isAbortError, storeRequestPromise, } from './util.js'; -import { Disposable } from '../../utils/Disposable.js'; export class IdbService extends Disposable { protected log?: Context['log']; @@ -17,7 +17,15 @@ export class IdbService extends Disposable { super(); this.log = log; this.addDispose(() => { - this.globalAbortController.abort(); + try { + this.globalAbortController.abort(); + } catch (err) { + if (err instanceof Error && err.message.includes('invocation')) { + // Ignore + return; + } + console.error('Error aborting global controller', err); + } }); this.db.addEventListener('versionchange', this.onVersionChange); this.addDispose(() => {