diff options
Diffstat (limited to 'packages/idb-bridge')
-rw-r--r-- | packages/idb-bridge/package.json | 2 | ||||
-rw-r--r-- | packages/idb-bridge/src/MemoryBackend.ts | 27 | ||||
-rw-r--r-- | packages/idb-bridge/src/util/errors.ts | 10 |
3 files changed, 33 insertions, 6 deletions
diff --git a/packages/idb-bridge/package.json b/packages/idb-bridge/package.json index 7ac39726b..3010f1f05 100644 --- a/packages/idb-bridge/package.json +++ b/packages/idb-bridge/package.json @@ -1,6 +1,6 @@ { "name": "idb-bridge", - "version": "0.0.11", + "version": "0.0.12", "description": "IndexedDB implementation that uses SQLite3 as storage", "main": "./build/index.js", "types": "./build/index.d.ts", diff --git a/packages/idb-bridge/src/MemoryBackend.ts b/packages/idb-bridge/src/MemoryBackend.ts index bb13a0223..b19c25cf0 100644 --- a/packages/idb-bridge/src/MemoryBackend.ts +++ b/packages/idb-bridge/src/MemoryBackend.ts @@ -32,6 +32,7 @@ import { InvalidStateError, InvalidAccessError, ConstraintError, + DataError, } from "./util/errors"; import BTree, { ISortedMapF } from "./tree/b+tree"; import compareKeys from "./util/cmp"; @@ -1386,11 +1387,27 @@ export class MemoryBackend implements Backend { ); } let indexData = index.modifiedData || index.originalData; - const indexKeys = getIndexKeys( - value, - indexProperties.keyPath, - indexProperties.multiEntry, - ); + let indexKeys; + try { + indexKeys = getIndexKeys( + value, + indexProperties.keyPath, + indexProperties.multiEntry, + ); + } catch (e) { + if (e instanceof DataError) { + const n = index.modifiedName || index.originalName; + const p = JSON.stringify(indexProperties.keyPath); + const m = `Failed to extract index keys from index ${n} for keyPath ${p}.`; + if (this.enableTracing) { + console.error(m); + console.error("value was", value); + } + throw new DataError(m); + } else { + throw e; + } + } for (const indexKey of indexKeys) { const existingRecord = indexData.get(indexKey); if (existingRecord) { diff --git a/packages/idb-bridge/src/util/errors.ts b/packages/idb-bridge/src/util/errors.ts index bbf9498c1..92de2ea90 100644 --- a/packages/idb-bridge/src/util/errors.ts +++ b/packages/idb-bridge/src/util/errors.ts @@ -42,6 +42,7 @@ const messages = { export class AbortError extends Error { constructor(message = messages.AbortError) { super(); + Object.setPrototypeOf(this, ConstraintError.prototype); this.name = "AbortError"; this.message = message; } @@ -50,6 +51,7 @@ export class AbortError extends Error { export class ConstraintError extends Error { constructor(message = messages.ConstraintError) { super(); + Object.setPrototypeOf(this, ConstraintError.prototype); this.name = "ConstraintError"; this.message = message; } @@ -58,6 +60,7 @@ export class ConstraintError extends Error { export class DataCloneError extends Error { constructor(message = messages.DataCloneError) { super(); + Object.setPrototypeOf(this, DataCloneError.prototype); this.name = "DataCloneError"; this.message = message; } @@ -66,6 +69,7 @@ export class DataCloneError extends Error { export class DataError extends Error { constructor(message = messages.DataError) { super(); + Object.setPrototypeOf(this, DataError.prototype); this.name = "DataError"; this.message = message; } @@ -74,6 +78,7 @@ export class DataError extends Error { export class InvalidAccessError extends Error { constructor(message = messages.InvalidAccessError) { super(); + Object.setPrototypeOf(this, InvalidAccessError.prototype); this.name = "InvalidAccessError"; this.message = message; } @@ -82,6 +87,7 @@ export class InvalidAccessError extends Error { export class InvalidStateError extends Error { constructor(message = messages.InvalidStateError) { super(); + Object.setPrototypeOf(this, InvalidStateError.prototype); this.name = "InvalidStateError"; this.message = message; } @@ -90,6 +96,7 @@ export class InvalidStateError extends Error { export class NotFoundError extends Error { constructor(message = messages.NotFoundError) { super(); + Object.setPrototypeOf(this, NotFoundError.prototype); this.name = "NotFoundError"; this.message = message; } @@ -98,6 +105,7 @@ export class NotFoundError extends Error { export class ReadOnlyError extends Error { constructor(message = messages.ReadOnlyError) { super(); + Object.setPrototypeOf(this, ReadOnlyError.prototype); this.name = "ReadOnlyError"; this.message = message; } @@ -106,6 +114,7 @@ export class ReadOnlyError extends Error { export class TransactionInactiveError extends Error { constructor(message = messages.TransactionInactiveError) { super(); + Object.setPrototypeOf(this, TransactionInactiveError.prototype); this.name = "TransactionInactiveError"; this.message = message; } @@ -114,6 +123,7 @@ export class TransactionInactiveError extends Error { export class VersionError extends Error { constructor(message = messages.VersionError) { super(); + Object.setPrototypeOf(this, VersionError.prototype); this.name = "VersionError"; this.message = message; } |