From 6b84ed49c34564fc7bd96cd69ba1c8f9acab5b6d Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 26 Sep 2023 13:24:05 +0530 Subject: [PATCH] fix: prevent showing stack traces 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..9c40a42 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, 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..0390bf2 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, 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"); },