Return treated data even after corrupt threshold

pull/5/head
eliot-akira 3 years ago
parent 143a08edde
commit 631d672af8
  1. 8
      lib/persistence.js

@ -214,18 +214,16 @@ class Persistence {
lineStream.on('end', () => { lineStream.on('end', () => {
// A bit lenient on corruption // A bit lenient on corruption
let err = null
if (length > 0 && corruptItems / length > this.corruptAlertThreshold) { if (length > 0 && corruptItems / length > this.corruptAlertThreshold) {
const corruptPercent = Math.floor(100 * this.corruptAlertThreshold) 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`)
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
} }
Object.keys(dataById).forEach(function (k) { Object.keys(dataById).forEach(function (k) {
tdata.push(dataById[k]) tdata.push(dataById[k])
}) })
cb(null, { data: tdata, indexes: indexes }) cb(err, { data: tdata, indexes: indexes })
}) })
lineStream.on('error', function (err) { lineStream.on('error', function (err) {

Loading…
Cancel
Save