diff --git a/lib/log/index.js b/lib/log/index.js index 7f53e89..bb5defd 100644 --- a/lib/log/index.js +++ b/lib/log/index.js @@ -712,7 +712,10 @@ function Log(filename, opts) { } await p(onDrain)() const [err1] = await p(onOverwritesFlushed)() - if (err1) return cb(err1) + if (err1) { + // prettier-ignore + return cb(new Error('Compact failed to pre-flush overwrites', { cause: err1 })) + } const startCompactTimestamp = Date.now() compacting = true @@ -724,7 +727,7 @@ function Log(filename, opts) { const [err2] = await p(fs.unlink.bind(fs))(filenameNew) if (err2 && err2.code !== 'ENOENT') { // prettier-ignore - return cb(new Error('Failed to get rid of previous compaction file when starting a new compact', {cause: err2})) + return cb(new Error('Compact failed to get rid of previous compacting log', { cause: err2 })) } const rafNew = RAF(filenameNew) @@ -808,7 +811,8 @@ function Log(filename, opts) { if (err3) { await p(rafNew.close.bind(rafNew))() compacting = false - return cb(err3) + // prettier-ignore + return cb(new Error('Compact failed while scanning-sifting the old log', { cause: err3 })) } await writeBlock(latestBlockIndexNew, latestBlockBufNew) @@ -819,12 +823,14 @@ function Log(filename, opts) { ]) if (err4 ?? err5) { compacting = false - return cb(err4 ?? err5) + // prettier-ignore + return cb(new Error('Compact failed to close log files', { cause: err4 ?? err5 })) } const [err6] = await p(fs.rename.bind(fs))(filenameNew, filename) if (err6) { compacting = false - return cb(err6) + // prettier-ignore + return cb(new Error('Compact failed to replace old log with new', { cause: err6 })) } raf = RAF(filename) latestBlockBuf = latestBlockBufNew @@ -838,9 +844,10 @@ function Log(filename, opts) { const duration = Date.now() - startCompactTimestamp debug2('Completed in %d ms', duration) deletedBytes = 0 - saveStats(function onSavedStatsAfterCompaction(err) { - if (err) debug2('Failed to save stats file: %s', err.message) - }) + const [err7] = await p(saveStats)() + if (err7) { + return cb(new Error('Compact failed to save stats file', { cause: err7 })) + } compactionProgress.set({ percent: 1, done: true, sizeDiff, holesFound }) for (const callback of waitingCompaction) callback() waitingCompaction.length = 0