aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-11-21 11:15:42 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-11-21 11:15:42 +0100
commit5b43bd857c6eb623ff93468046d8bc08226d9ca0 (patch)
treefdd3ba1e766a70d9de23526b1737245a74d0ceac /packages
parentf797f16e2f5b6ccfa5b1301becc07302ab2131a2 (diff)
improve error messages
Diffstat (limited to 'packages')
-rw-r--r--packages/idb-bridge/package.json2
-rw-r--r--packages/idb-bridge/src/MemoryBackend.ts36
2 files changed, 30 insertions, 8 deletions
diff --git a/packages/idb-bridge/package.json b/packages/idb-bridge/package.json
index 3010f1f05..19c28245b 100644
--- a/packages/idb-bridge/package.json
+++ b/packages/idb-bridge/package.json
@@ -1,6 +1,6 @@
{
"name": "idb-bridge",
- "version": "0.0.12",
+ "version": "0.0.13",
"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 b19c25cf0..792ae4cd3 100644
--- a/packages/idb-bridge/src/MemoryBackend.ts
+++ b/packages/idb-bridge/src/MemoryBackend.ts
@@ -1329,14 +1329,36 @@ export class MemoryBackend implements Backend {
key = storeReq.key;
value = storeReq.value;
} else {
- const storeKeyResult: StoreKeyResult = makeStoreKeyValue(
- storeReq.value,
- storeReq.key,
+ const keygen =
objectStoreMapEntry.store.modifiedKeyGenerator ||
- objectStoreMapEntry.store.originalKeyGenerator,
- schema.objectStores[storeReq.objectStoreName].autoIncrement,
- schema.objectStores[storeReq.objectStoreName].keyPath,
- );
+ objectStoreMapEntry.store.originalKeyGenerator;
+ const autoIncrement =
+ schema.objectStores[storeReq.objectStoreName].autoIncrement;
+ const keyPath = schema.objectStores[storeReq.objectStoreName].keyPath;
+ let storeKeyResult: StoreKeyResult;
+ try {
+ storeKeyResult = makeStoreKeyValue(
+ storeReq.value,
+ storeReq.key,
+ keygen,
+ autoIncrement,
+ keyPath,
+ );
+ } catch (e) {
+ if (e instanceof DataError) {
+ const kp = JSON.stringify(keyPath);
+ const n = storeReq.objectStoreName;
+ const m = `Could not extract key from value, objectStore=${n}, keyPath=${kp}`;
+ if (this.enableTracing) {
+ console.error(e);
+ console.error("value was:", storeReq.value);
+ console.error("key was:", storeReq.key);
+ }
+ throw new DataError(m);
+ } else {
+ throw e;
+ }
+ }
key = storeKeyResult.key;
value = storeKeyResult.value;
objectStoreMapEntry.store.modifiedKeyGenerator =