Просмотр исходного кода

Preserve all error information when cleanup of copied file fails

Simon Detheridge 6 лет назад
Родитель
Сommit
5d5d325691
1 измененных файлов с 10 добавлено и 12 удалено
  1. 10 12
      services/filestore/app/js/MigrationPersistor.js

+ 10 - 12
services/filestore/app/js/MigrationPersistor.js

@@ -111,13 +111,21 @@ module.exports = function(primary, fallback) {
 
       await primary.promises.sendStream(destBucket, destKey, stream, sourceMd5)
     } catch (err) {
-      let error = err
+      const error = new WriteError({
+        message: 'unable to copy file to destination persistor',
+        info: {
+          sourceBucket,
+          destBucket,
+          sourceKey,
+          destKey
+        }
+      }).withCause(err)
       metrics.inc('fallback.copy.failure')
 
       try {
         await primary.promises.deleteFile(destBucket, destKey)
       } catch (err) {
-        error = new WriteError({
+        error.info.cleanupError = new WriteError({
           message: 'unable to clean up destination copy artifact',
           info: {
             destBucket,
@@ -126,16 +134,6 @@ module.exports = function(primary, fallback) {
         }).withCause(err)
       }
 
-      error = new WriteError({
-        message: 'unable to copy file to destination persistor',
-        info: {
-          sourceBucket,
-          destBucket,
-          sourceKey,
-          destKey
-        }
-      }).withCause(error)
-
       logger.warn({ error }, 'failed to copy file from fallback')
       throw error
     }