From 691ec36cdcb43c94bff0b6b20fac4f19a4137d2b Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 26 Sep 2023 13:24:05 +0530 Subject: [PATCH] fix: prevent showing stack trace on the course of error --- dist/index.js | 35 ++++++++++++++++++++++------------- index.js | 35 ++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/dist/index.js b/dist/index.js index f89b554..e7423fb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1840,20 +1840,31 @@ const toUrlFormat = (item) => { const exec = (cmd, args = []) => new Promise((resolve, reject) => { - const app = spawn(cmd, args, { stdio: "pipe" }); + const app = spawn(cmd, args); + let stdout = ""; - app.stdout.on("data", (data) => { - stdout = data; - }); + if (app.stdout) { + app.stdout.on("data", (data) => { + stdout += data.toString(); + }); + } + + let stderr = ""; + if (app.stderr) { + app.stderr.on("data", (data) => { + stderr += data.toString(); + }); + } + app.on("close", (code) => { if (code !== 0 && !stdout.includes("nothing to commit")) { - err = new Error(`Invalid status code: ${code}`); - err.code = code; - return reject(err); + return reject({ code, message: stderr }); } - return resolve(code); + + return resolve({ code, stdout }); }); - app.on("error", reject); + + app.on("error", () => reject({ code: 1, message: stderr })); }); /** @@ -1981,8 +1992,7 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + return tools.exit.failure(err.message); } tools.exit.success("Wrote to README"); } @@ -2032,8 +2042,7 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + return tools.exit.failure(err.message); } tools.exit.success("Pushed to remote repository"); }, diff --git a/index.js b/index.js index 7b27274..f613300 100644 --- a/index.js +++ b/index.js @@ -57,20 +57,31 @@ const toUrlFormat = (item) => { const exec = (cmd, args = []) => new Promise((resolve, reject) => { - const app = spawn(cmd, args, { stdio: "pipe" }); + const app = spawn(cmd, args); + let stdout = ""; - app.stdout.on("data", (data) => { - stdout = data; - }); + if (app.stdout) { + app.stdout.on("data", (data) => { + stdout += data.toString(); + }); + } + + let stderr = ""; + if (app.stderr) { + app.stderr.on("data", (data) => { + stderr += data.toString(); + }); + } + app.on("close", (code) => { if (code !== 0 && !stdout.includes("nothing to commit")) { - err = new Error(`Invalid status code: ${code}`); - err.code = code; - return reject(err); + return reject({ code, message: stderr }); } - return resolve(code); + + return resolve({ code, stdout }); }); - app.on("error", reject); + + app.on("error", () => reject({ code: 1, message: stderr })); }); /** @@ -198,8 +209,7 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + return tools.exit.failure(err.message); } tools.exit.success("Wrote to README"); } @@ -249,8 +259,7 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + return tools.exit.failure(err.message); } tools.exit.success("Pushed to remote repository"); },