Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Mar 25, 2024
1 parent 9df8cfe commit 049dd28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ async function invoke(Cls) {
core.setFailed(reason);
});

if (!(Cls.prototype instanceof BaseAction)) {
throw new Error("Action class must extend BaseAction");
}
let obj;
let rendered;
try {
if (!(Cls.prototype instanceof BaseAction)) {
throw new Error("Action class must extend BaseAction");
}

const obj = new Cls();
const rendered = await obj.render();
if (rendered == null) {
obj = new Cls();
rendered = await obj.render();
if (rendered == null) {
return;
}
} catch (e) {
core.setFailed(e.message);
return;
}

Expand Down
16 changes: 8 additions & 8 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ describe("invoke", function () {
it("throws an exception if class is not instance of BaseAction", async function () {
class BadTestAction {}

await assert.rejects(invoke(BadTestAction), {
name: "Error",
message: "Action class must extend BaseAction",
});
const setFailed = sinon.spy(core, "setFailed");
await invoke(BadTestAction);
assert(setFailed.calledOnce);
assert(setFailed.calledWith("Action class must extend BaseAction"));
});

it("throws an exception if class has no render() function", async function () {
class BadTestAction extends BaseAction {}

await assert.rejects(invoke(BadTestAction), {
name: "Error",
message: "render not implemented",
});
const setFailed = sinon.spy(core, "setFailed");
await invoke(BadTestAction);
assert(setFailed.calledOnce);
assert(setFailed.calledWith("render not implemented"));
});

it("fails the build if writeBadge throws an error", async function () {
Expand Down

0 comments on commit 049dd28

Please sign in to comment.