diff --git a/bin/util.js b/bin/util.js index d09c292..177f5b4 100644 --- a/bin/util.js +++ b/bin/util.js @@ -225,20 +225,28 @@ let download = async ({ url, outputPath, key, archive }) => { return; } - await pipeline( - got - .stream(url) - .on("downloadProgress", (progress) => { - printProgress(progress); - }) - .on("end", () => { - endPrintProgress(); - }), - fs.createWriteStream(outputPath) - ); - - if (key && archive && !getIsInArchive({ key, archive })) { - writeToArchive({ key, archive }); + try { + await pipeline( + got + .stream(url) + .on("downloadProgress", (progress) => { + printProgress(progress); + }) + .on("end", () => { + endPrintProgress(); + + if (key && archive && !getIsInArchive({ key, archive })) { + writeToArchive({ key, archive }); + } + }), + fs.createWriteStream(outputPath) + ); + } catch (error) { + if (fs.existsSync(outputPath)) { + fs.unlinkSync(outputPath); + } + + throw error; } }; diff --git a/bin/validate.js b/bin/validate.js index 4c0300b..d27325d 100644 --- a/bin/validate.js +++ b/bin/validate.js @@ -2,7 +2,7 @@ const logError = (msg, error) => { console.error(msg); if (error) { - console.error(error); + console.error(error.message); } };