Skip to content

Commit

Permalink
fix: prevent showing stack traces on the course of error
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Sep 26, 2023
1 parent 762c517 commit 6b84ed4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
35 changes: 22 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
});

/**
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
},
Expand Down
35 changes: 22 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
});

/**
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
},
Expand Down

0 comments on commit 6b84ed4

Please sign in to comment.