diff --git a/dist/index.js b/dist/index.js index f89b554..a13cf49 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, stderr }); } - return resolve(code); + + return resolve(); }); - app.on("error", reject); + + app.on("error", () => reject({ code: 1, stderr })); }); /** @@ -1981,8 +1992,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Wrote to README"); } @@ -2032,8 +2043,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + 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 7b27274..40d573a 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, stderr }); } - return resolve(code); + + return resolve(); }); - app.on("error", reject); + + app.on("error", () => reject({ code: 1, stderr })); }); /** @@ -198,8 +209,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Wrote to README"); } @@ -249,8 +260,8 @@ Toolkit.run( try { await commitFile(); } catch (err) { - tools.log.debug("Something went wrong"); - return tools.exit.failure(err); + const message = `Exit code: ${err.code}\n${err.stderr}`; + return tools.exit.failure(message); } tools.exit.success("Pushed to remote repository"); }, 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": [],