Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/warn-failed-requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/slack-github-action": minor
---

feat: log a warning with the reason a request failed when the "errors" option is not true
2 changes: 1 addition & 1 deletion docs/additional-configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ There are some additional, possibly useful, customization options for workflows.

Invalid API requests or unexpected webhook payloads cause a failing response that can be used to fail the GitHub Actions step with the `errors` option.

The `errors` option defaults to `false` so failed requests do not cause the step to fail. This result can still be gathered from the `ok` output.
The `errors` option defaults to `false` so failed requests log a warning but don't cause the step to fail. The step's result can still be gathered from the `ok` output.

```yaml
- name: Attempt to call an unknown method
Expand Down
1 change: 1 addition & 0 deletions src/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default async function send(core) {
core.setFailed(error);
throw new SlackError(core, error);
}
core.warning(`Failed to send the request: ${error.message}`);
}
}

Expand Down
42 changes: 42 additions & 0 deletions test/send.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from "node:assert";
import { beforeEach, describe, it } from "node:test";
import webapi from "@slack/web-api";
import send from "../src/send.js";
import { mocks } from "./index.spec.js";

Expand Down Expand Up @@ -75,4 +76,45 @@ describe("send", () => {
assert.ok(mocks.core.setOutput.getCall(2).lastArg >= 0);
});
});

describe("logging", async () => {
it("warns of the failed request when errors are not fatal", async () => {
mocks.core.getInput.withArgs("method").returns("chat.postMessage");
mocks.core.getInput.withArgs("token").returns("xoxb-example");
mocks.core.getInput.withArgs("payload").returns('"text": "hello"');
mocks.calls.rejects(
new webapi.WebAPIPlatformError({ ok: false, error: "invalid_auth" }),
);
await send(mocks.core);
assert.strictEqual(mocks.core.setFailed.called, false);
assert.equal(mocks.core.warning.getCalls().length, 1);
assert.match(mocks.core.warning.getCall(0).firstArg, /invalid_auth/);
});

it("warns of the failed webhook when errors are not fatal", async () => {
mocks.core.getInput
.withArgs("webhook")
.returns("https://hooks.slack.com");
mocks.core.getInput.withArgs("webhook-type").returns("webhook-trigger");
mocks.core.getInput.withArgs("payload").returns('"greetings": "hello"');
mocks.webhook.trigger.rejects(new Error("invalid_payload"));
await send(mocks.core);
assert.strictEqual(mocks.core.setFailed.called, false);
assert.equal(mocks.core.warning.getCalls().length, 1);
assert.match(mocks.core.warning.getCall(0).firstArg, /invalid_payload/);
});

it("fails the step without warning when errors are fatal", async () => {
mocks.core.getBooleanInput.withArgs("errors").returns(true);
mocks.core.getInput.withArgs("method").returns("chat.postMessage");
mocks.core.getInput.withArgs("token").returns("xoxb-example");
mocks.core.getInput.withArgs("payload").returns('"text": "hello"');
mocks.calls.rejects(
new webapi.WebAPIPlatformError({ ok: false, error: "invalid_auth" }),
);
await assert.rejects(send(mocks.core));
assert.ok(mocks.core.setFailed.called);
assert.strictEqual(mocks.core.warning.called, false);
});
});
});
Loading