From 5cd4aff6a21266fa6d87a3acf3097f2a828f78bd Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 26 Sep 2023 13:24:05 +0530 Subject: [PATCH 1/3] 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"); }, From ec436f8b41af240bb2d8beae6d311201033ed79f Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 27 Sep 2023 22:08:40 +0530 Subject: [PATCH 2/3] chore: bump version to `v0.4.3` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8e99cc7..6b50556 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-activity-readme", - "version": "0.4.2", + "version": "0.4.3", "description": "Updates README with the recent GitHub activity of a user", "main": "index.js", "keywords": [], From 934ea840f8b8c600e79e1b070aa2dd3a64f1053a Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 28 Sep 2023 18:01:17 +0530 Subject: [PATCH 3/3] refactor: log exit code in addition to the error message --- dist/index.js | 12 +++++++----- index.js | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index e7423fb..a13cf49 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1858,13 +1858,13 @@ const exec = (cmd, args = []) => app.on("close", (code) => { if (code !== 0 && !stdout.includes("nothing to commit")) { - return reject({ code, message: stderr }); + return reject({ code, stderr }); } - return resolve({ code, stdout }); + return resolve(); }); - app.on("error", () => reject({ code: 1, message: stderr })); + app.on("error", () => reject({ code: 1, stderr })); }); /** @@ -1992,7 +1992,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - return tools.exit.failure(err.message); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Wrote to README"); } @@ -2042,7 +2043,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - return tools.exit.failure(err.message); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Pushed to remote repository"); }, diff --git a/index.js b/index.js index f613300..40d573a 100644 --- a/index.js +++ b/index.js @@ -75,13 +75,13 @@ const exec = (cmd, args = []) => app.on("close", (code) => { if (code !== 0 && !stdout.includes("nothing to commit")) { - return reject({ code, message: stderr }); + return reject({ code, stderr }); } - return resolve({ code, stdout }); + return resolve(); }); - app.on("error", () => reject({ code: 1, message: stderr })); + app.on("error", () => reject({ code: 1, stderr })); }); /** @@ -209,7 +209,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - return tools.exit.failure(err.message); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Wrote to README"); } @@ -259,7 +260,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - return tools.exit.failure(err.message); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Pushed to remote repository"); },