Skip to content

TypeError: err.toJSON is not a function when webhook URL is invalid #511

Description

@pcolby

This took a bit for me to track down (my own mistake), thanks to the real error not being shown in the action. If, for example, I accidentally quote the webhook URL, like:

           - name: Notify Slack
              uses: slackapi/slack-github-action@v2
              with:
                  errors: true
                  payload: <redacted>
                  webhook: ${{ toJSON(secrets.SLACK_WEBHOOK_URL) }}
                  webhook-type: webhook-trigger

I get an exception thrown:

Run slackapi/slack-github-action@v2
Error: TypeError: err.toJSON is not a function

Error: err.toJSON is not a function
TypeError: err.toJSON is not a function
    at Webhook.post (file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/webhook.js:36:1)
    at post (file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/send.js:35:1)
    at send (file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/send.js:15:1)
    at file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/index.js:9:1
file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/webhook.js:36
      const response = err.toJSON();
^
TypeError: err.toJSON is not a function
    at Webhook.post (file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/webhook.js:36:1)
    at post (file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/send.js:35:1)
    at send (file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/send.js:15:1)
    at file:///home/runner/work/_actions/slackapi/slack-github-action/v2/src/index.js:9:1

It looks like the catch block is assuming the exception will always have a toJSON function, but in my case it obviously doesn't.

The fix of course, was to remove the erroneous toJSON(...) wrapper from the webhook input, but it would have saved me a lot of time if the exception was handled better by thi action.

Note, the err.toJSON in the exception is unrelated to the toJSON in my input - its only coincidental that we both used (different) toJSON functions (JavaScript vs GitHub Expression respectively).

Cheers.

Activity

  1. added theissue type on Nov 17, 2025
  2. added this to the 2.x milestone on Nov 17, 2025
  3. mwbrooks commented on Nov 17, 2025

    @mwbrooks
    Member

    Hi @pcolby 👋🏻

    Oof, this must have taken some time to track down. Sorry that we put that on you. 🙇🏻

    We've had a few iterations to surface the right level of errors in the GitHub Action and I think you've found an edge-case. Thanks a lot for the details, code example, and resolution. I think this goes a long way in helping us reproduce it and patch it.

    @zimeg Since you've made big strides in improving the errors, what are your thoughts on this one?

  4. mwbrooks commented on Nov 22, 2025

    @mwbrooks
    Member

    @pcolby I had a chat with @zimeg async and they agree that it's a bug 🐛 So we'll keep this issue open and follow-up with a PR.

    Thanks again for taking the time to submit the issue and workaround! 🙇🏻

  5. modified the milestones: 2.x, 3.x on Mar 13, 2026
  6. added a commit that references this issue on Mar 24, 2026
    83741c4
  7. modified the milestones: 3.x, 4.x on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions