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

Action fails silently when the API call fails #63

Closed
4 of 10 tasks
kitchoi opened this issue Feb 22, 2022 · 4 comments · Fixed by #333
Closed
4 of 10 tasks

Action fails silently when the API call fails #63

kitchoi opened this issue Feb 22, 2022 · 4 comments · Fixed by #333
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@kitchoi
Copy link

kitchoi commented Feb 22, 2022

Description

There may have been a network issue which causes an API call to fail. However, the workflow did not fail.
The workflow was using Slack Bot Token and a Channel ID while posting a payload.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

package version: 1.16.0

node version:

OS version(s): Ubuntu 20

Steps to reproduce:

  1. With a step looking like this
  users: slackapi/[email protected]
  with:
    channel-id: XXXXX
    payload: {
    "text": "Some text",
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": "*Some text*"
        }
      }
    ]
  }
  env:
    SLACK_BOT_TOKEN: ***
  1. Not sure how you could simulate Slack API going down... I am guessing you want this line to raise an exception:
    await web.chat.postMessage({ channel: channelId, text: message, ...(payload || {}) });

It is worth noting that the said step runs fine many times, so I am pretty sure that the payload and parameters are set correctly.

Expected result:

The step causes the workflow to error

Actual result:

The workflow passes.

Attachments:

Error logged:


(node:2465) UnhandledPromiseRejectionWarning: Error: An API error occurred: fatal_error
    at Object.platformErrorFromResult (/home/runner/work/_actions/slackapi/slack-github-action/v1.16.0/dist/index.js:5082:33)
    at WebClient.apiCall (/home/runner/work/_actions/slackapi/slack-github-action/v1.16.0/dist/index.js:4685:28)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:2465) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2465) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@seratch seratch added bug Something isn't working enhancement New feature or request labels Feb 22, 2022
@seratch seratch added this to the 1.19 milestone Feb 22, 2022
@seratch
Copy link
Member

seratch commented Feb 22, 2022

Hi @kitchoi, thanks for taking the time to report this issue. At that timing, the Slack server-side had an incident: https://status.slack.com/2022-02-22 If this GitHub action does not result in failure in the scenario, the error handling should be improved in future versions.

@kitchoi
Copy link
Author

kitchoi commented Feb 22, 2022

Thank you @seratch for your prompt response.

In case this helps, I was able to reproduce a similar silent failure by deliberately supplying a channel ID that does not exist:

(node:1680) UnhandledPromiseRejectionWarning: Error: An API error occurred: channel_not_found
    at Object.platformErrorFromResult (/home/runner/work/_actions/slackapi/slack-github-action/v1.16.0/dist/index.js:5082:[33](https://github.com/organization/repo/runs/5295133106?check_suite_focus=true#step:7:33))
    at WebClient.apiCall (/home/runner/work/_actions/slackapi/slack-github-action/v1.16.0/dist/index.js:4685:28)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:1680) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1680) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@seratch
Copy link
Member

seratch commented Feb 22, 2022

Thanks. Yes, I managed to reproduce the issue on my end.

@seratch seratch modified the milestones: 1.19, 1.20 May 4, 2022
@seratch seratch modified the milestones: 1.20, 1.x Aug 15, 2022
@zimeg zimeg modified the milestones: 1.x, 2.x, 2.0 Nov 15, 2024
@zimeg zimeg linked a pull request Nov 15, 2024 that will close this issue
8 tasks
@zimeg
Copy link
Member

zimeg commented Nov 15, 2024

👋 With the @2.0.0 release we now have the errors input option that can be set to true to cause the step to fail if the request fails and the message can't be sent for some reason:

- name: Send a message to nowhere
  uses: slackapi/[email protected]
  with:
    errors: true
    method: chat.postMessage
    token: ${{ secrets.SLACK_BOT_TOKEN }}
    payload: |
      channel: ""
      text: "Greetings!"

This setup will cause the step to fail with the following error:

SlackError: An API error occurred: channel_not_found

In addition to this, the retries option might be useful for attempting failed requests multiple times if that's preferred in your workflows:

- name: Attempt a burst of requests
  uses: slackapi/[email protected]
  with:
    method: chat.postMessage
    retries: RAPID
    token: ${{ secrets.SLACK_BOT_TOKEN }}
    payload: |
      channel: ${{ secrets.SLACK_CHANNEL_ID }}
      text: "Greetings!"

I'm hoping these options together might be useful when handling failed API calls 🙏 I'll close this issue for now, but please do feel free to comment with more questions or open another issue whenever!

@zimeg zimeg closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants