Preserve all error information when cleanup of copied file fails

This commit is contained in:
Simon Detheridge 2020-01-29 11:09:20 +00:00
parent b4b7fd226e
commit 5d5d325691

View file

@ -111,22 +111,7 @@ 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({
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({
message: 'unable to copy file to destination persistor', message: 'unable to copy file to destination persistor',
info: { info: {
sourceBucket, sourceBucket,
@ -134,7 +119,20 @@ module.exports = function(primary, fallback) {
sourceKey, sourceKey,
destKey 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') logger.warn({ error }, 'failed to copy file from fallback')
throw error throw error