Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent stack trace on the course of error #113

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 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, stderr });
}
return resolve(code);

return resolve();
});
app.on("error", reject);

app.on("error", () => reject({ code: 1, stderr }));
});

/**
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
},
Expand Down
37 changes: 24 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);
tuunit marked this conversation as resolved.
Show resolved Hide resolved

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 }));
});

/**
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [],
Expand Down