diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-11-21 11:15:42 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-11-21 11:15:42 +0100 |
commit | 5b43bd857c6eb623ff93468046d8bc08226d9ca0 (patch) | |
tree | fdd3ba1e766a70d9de23526b1737245a74d0ceac /packages/idb-bridge/src/MemoryBackend.ts | |
parent | f797f16e2f5b6ccfa5b1301becc07302ab2131a2 (diff) | |
download | wallet-core-5b43bd857c6eb623ff93468046d8bc08226d9ca0.tar.xz |
improve error messages
Diffstat (limited to 'packages/idb-bridge/src/MemoryBackend.ts')
-rw-r--r-- | packages/idb-bridge/src/MemoryBackend.ts | 36 |
1 files changed, 29 insertions, 7 deletions
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 = |