From 5d5d325691cf3c1b4f13294a1bf3003c956ed9a3 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Wed, 29 Jan 2020 11:09:20 +0000 Subject: [PATCH] Preserve all error information when cleanup of copied file fails --- .../filestore/app/js/MigrationPersistor.js | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/services/filestore/app/js/MigrationPersistor.js b/services/filestore/app/js/MigrationPersistor.js index fdc31368a3..3a4789693b 100644 --- a/services/filestore/app/js/MigrationPersistor.js +++ b/services/filestore/app/js/MigrationPersistor.js @@ -111,22 +111,7 @@ module.exports = function(primary, fallback) { await primary.promises.sendStream(destBucket, destKey, stream, sourceMd5) } catch (err) { - let error = err - metrics.inc('fallback.copy.failure') - - try { - await primary.promises.deleteFile(destBucket, destKey) - } catch (err) { - error = new WriteError({ - message: 'unable to clean up destination copy artifact', - info: { - destBucket, - destKey - } - }).withCause(err) - } - - error = new WriteError({ + const error = new WriteError({ message: 'unable to copy file to destination persistor', info: { sourceBucket, @@ -134,7 +119,20 @@ module.exports = function(primary, fallback) { sourceKey, destKey } - }).withCause(error) + }).withCause(err) + metrics.inc('fallback.copy.failure') + + try { + await primary.promises.deleteFile(destBucket, destKey) + } catch (err) { + error.info.cleanupError = new WriteError({ + message: 'unable to clean up destination copy artifact', + info: { + destBucket, + destKey + } + }).withCause(err) + } logger.warn({ error }, 'failed to copy file from fallback') throw error