improve error messages

This commit is contained in:
Florian Dold 2019-11-21 11:15:42 +01:00
parent f797f16e2f
commit 5b43bd857c
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 30 additions and 8 deletions

View File

@ -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",

View File

@ -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 =