Selaa lähdekoodia

Preserve all error information when cleanup of copied file fails

Simon Detheridge 6 vuotta sitten
vanhempi
sitoutus
5d5d325691
1 muutettua tiedostoa jossa 10 lisäystä ja 12 poistoa
  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)
       await primary.promises.sendStream(destBucket, destKey, stream, sourceMd5)
     } catch (err) {
     } 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')
       metrics.inc('fallback.copy.failure')
 
 
       try {
       try {
         await primary.promises.deleteFile(destBucket, destKey)
         await primary.promises.deleteFile(destBucket, destKey)
       } catch (err) {
       } catch (err) {
-        error = new WriteError({
+        error.info.cleanupError = new WriteError({
           message: 'unable to clean up destination copy artifact',
           message: 'unable to clean up destination copy artifact',
           info: {
           info: {
             destBucket,
             destBucket,
@@ -126,16 +134,6 @@ module.exports = function(primary, fallback) {
         }).withCause(err)
         }).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')
       logger.warn({ error }, 'failed to copy file from fallback')
       throw error
       throw error
     }
     }