feat: log the reason a request failed when errors are not fatal (#666)

Co-authored-by: Eden Zimbelman <[email protected]>
This commit is contained in:
Deepak Nayak
2026-08-11 15:07:47 -07:00
committed by GitHub
co-authored by Eden Zimbelman
parent 1d8e1efa99
commit c28a16bcdb
4 changed files with 49 additions and 1 deletions
+5
View File
@@ -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
+1 -1
View File
@@ -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
+1
View File
@@ -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}`);
}
}
+42
View File
@@ -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";
@@ -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);
});
});
});