diff --git a/src/matrix/storage/idb/Store.ts b/src/matrix/storage/idb/Store.ts index 9c49dc57..64943d1b 100644 --- a/src/matrix/storage/idb/Store.ts +++ b/src/matrix/storage/idb/Store.ts @@ -36,7 +36,7 @@ class QueryTargetWrapper { get keyPath(): string | string[] { if ("objectStore" in this._qt) { - return (this._qt as IDBIndex).objectStore.keyPath; + return this._qt.objectStore.keyPath; } else { return this._qt.keyPath; } diff --git a/src/matrix/storage/idb/error.ts b/src/matrix/storage/idb/error.ts index 1c6875fb..bd3fb0a8 100644 --- a/src/matrix/storage/idb/error.ts +++ b/src/matrix/storage/idb/error.ts @@ -17,13 +17,31 @@ limitations under the License. import { StorageError } from "../common"; +function _sourceName(source: IDBIndex | IDBObjectStore): string { + return "objectStore" in source ? + `${source.objectStore.name}.${source.name}` : + source.name; +} + +function _sourceDatabase(source: IDBIndex | IDBObjectStore): string { + return "objectStore" in source ? + source.objectStore.transaction.db.name : + source.transaction.db.name; +} + export class IDBError extends StorageError { storeName: string; databaseName: string; - constructor(message: string, source, cause: DOMException | null = null) { - const storeName = source?.name || ""; - const databaseName = source?.transaction?.db?.name || ""; + constructor(message: string, source: IDBIndex | IDBCursor | IDBObjectStore, cause: DOMException | null = null) { + let storeName: string, databaseName: string; + if (source instanceof IDBCursor) { + storeName = _sourceName(source.source); + databaseName = _sourceDatabase(source.source); + } else { + storeName = _sourceName(source); + databaseName = _sourceDatabase(source); + } let fullMessage = `${message} on ${databaseName}.${storeName}`; if (cause) { fullMessage += ": "; @@ -52,7 +70,7 @@ export class IDBRequestError extends IDBError { } export class IDBRequestAttemptError extends IDBError { - constructor(method: string, source, cause: DOMException, params: any[]) { + constructor(method: string, source: IDBIndex | IDBObjectStore, cause: DOMException, params: any[]) { super(`${method}(${params.map(p => JSON.stringify(p)).join(", ")}) failed`, source, cause); } }