Skip to content

Commit

Permalink
ignore illegal abort invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Nov 30, 2024
1 parent 63e392f commit 87aa284
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/many-roses-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@verdant-web/persistence-sqlite': patch
'@verdant-web/store': patch
---

Ignore illegal invocation error from abort controller
13 changes: 10 additions & 3 deletions packages/persistence-sqlite/src/SqliteService.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
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();

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

Expand Down
12 changes: 10 additions & 2 deletions packages/store/src/persistence/idb/IdbService.ts
Original file line number Diff line number Diff line change
@@ -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'];
Expand All @@ -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(() => {
Expand Down

0 comments on commit 87aa284

Please sign in to comment.