diff --git a/package.json b/package.json index 98ea11c..7dd5378 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jungle-db", - "version": "0.4.1", + "version": "0.4.2", "main": "dist/node.js", "private": true, "scripts": { diff --git a/src/main/platform/browser/IDBBackend.js b/src/main/platform/browser/IDBBackend.js index c9a476e..05a9e7b 100644 --- a/src/main/platform/browser/IDBBackend.js +++ b/src/main/platform/browser/IDBBackend.js @@ -242,10 +242,14 @@ class IDBBackend { openCursorRequest.onsuccess = event => { const cursor = event.target.result; if (cursor) { - if (callback(cursor.primaryKey)) { - cursor.continue(); - } else { - resolve(); + try { + if (callback(cursor.primaryKey)) { + cursor.continue(); + } else { + resolve(); + } + } catch (e) { + reject(e); } } else { resolve(); diff --git a/src/main/platform/browser/PersistentIndex.js b/src/main/platform/browser/PersistentIndex.js index 325894f..5009957 100644 --- a/src/main/platform/browser/PersistentIndex.js +++ b/src/main/platform/browser/PersistentIndex.js @@ -72,7 +72,11 @@ class PersistentIndex { request.onsuccess = event => { const cursor = event.target.result; if (cursor) { - results.push(this._objectStore.decode(cursor.value, cursor.primaryKey)); + try { + results.push(this._objectStore.decode(cursor.value, cursor.primaryKey)); + } catch (e) { + reject(e); + } cursor.continue(); } else { resolve(results); @@ -130,7 +134,11 @@ class PersistentIndex { } // Only iterate until key changes. if (cursor && maxKey === cursor.key) { - results.push(this._objectStore.decode(cursor.value, cursor.primaryKey)); + try { + results.push(this._objectStore.decode(cursor.value, cursor.primaryKey)); + } catch (e) { + reject(e); + } cursor.continue(); } else { resolve(results); @@ -193,7 +201,11 @@ class PersistentIndex { } // Only iterate until key changes. if (cursor && maxKey === cursor.key) { - results.push(this._objectStore.decode(cursor.value, cursor.primaryKey)); + try { + results.push(this._objectStore.decode(cursor.value, cursor.primaryKey)); + } catch (e) { + reject(e); + } cursor.continue(); } else { resolve(results); diff --git a/src/main/platform/nodejs/LevelDBBackend.js b/src/main/platform/nodejs/LevelDBBackend.js index 8e0cb24..40c49d3 100644 --- a/src/main/platform/nodejs/LevelDBBackend.js +++ b/src/main/platform/nodejs/LevelDBBackend.js @@ -273,10 +273,14 @@ class LevelDBBackend { const stream = this._dbBackend.createReadStream(LevelDBTools.convertKeyRange(query, { 'values': false, 'keys': true, 'reverse': !ascending })); let stopped = false; stream.on('data', data => { - if (!callback(data)) { - stopped = true; - stream.pause(); - stream.destroy(); + try { + if (!callback(data)) { + stopped = true; + stream.pause(); + stream.destroy(); + } + } catch (e) { + error(e); } }) .on('error', err => {