From 631d672af8c54cc5e31b583ff812a14f7ab02267 Mon Sep 17 00:00:00 2001 From: eliot-akira Date: Sun, 3 Oct 2021 04:40:43 +0200 Subject: [PATCH] Return treated data even after corrupt threshold --- lib/persistence.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/persistence.js b/lib/persistence.js index 50a77d3..38578b9 100755 --- a/lib/persistence.js +++ b/lib/persistence.js @@ -214,18 +214,16 @@ class Persistence { lineStream.on('end', () => { // A bit lenient on corruption + let err = null if (length > 0 && corruptItems / length > this.corruptAlertThreshold) { - const corruptPercent = Math.floor(100 * this.corruptAlertThreshold) - const err = new Error(`More than ${corruptPercent}% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss`) - cb(err, null) - return + err = new Error(`More than ${Math.floor(100 * this.corruptAlertThreshold)}% of the data file is corrupt, the wrong beforeDeserialization hook may be used. Cautiously refusing to start NeDB to prevent dataloss`) } Object.keys(dataById).forEach(function (k) { tdata.push(dataById[k]) }) - cb(null, { data: tdata, indexes: indexes }) + cb(err, { data: tdata, indexes: indexes }) }) lineStream.on('error', function (err) {