From 3a21191fba443a13c4c30e7bef3dd82318bca4d7 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 10 Jul 2024 19:09:02 +0200 Subject: [PATCH] tgz: fix error handling --- src/backupformat/tgz.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backupformat/tgz.js b/src/backupformat/tgz.js index 7489009ae..66247adab 100644 --- a/src/backupformat/tgz.js +++ b/src/backupformat/tgz.js @@ -39,19 +39,19 @@ function addToPack(pack, header, options) { const packEntry = safe(() => pack.entry(header, function (error) { if (error) { debug(`addToPack: error adding ${header.name} ${header.type} ${error.message}`); - reject(error); + reject(new BoxError(BoxError.FS_ERROR, error.message)); } else { debug(`addToPack: added ${header.name} ${header.type}`); resolve(); } })); - if (packEntry && options?.input) { - safe(stream.pipeline(options.input, packEntry)); // background + if (!packEntry) { + return reject(new BoxError(BoxError.FS_ERROR, `Failed to add ${header.name}: ${safe.error.message}`)); } - if (!packEntry) { - reject(new Error(`Failed to add ${header.name}: ${safe.error.message}`)); + if (options?.input) { + safe(stream.pipeline(options.input, packEntry), { debug }); // background. rely on pack.entry callback for promise completion } }); } @@ -124,7 +124,7 @@ async function tarPack(dataLayout, encryption, uploader, progressCallback) { pack.finalize(); - const [error] = await safe(pipeline); + const [error] = await pipeline; // already wrapped in safe() if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `tarPack pipeline error: ${error.message}`); debug(`tarPack: pipeline finished: ${JSON.stringify(ps.stats())}`);