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.
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:
I get an exception thrown:
It looks like the
catchblock is assuming the exception will always have atoJSONfunction, but in my case it obviously doesn't.The fix of course, was to remove the erroneous
toJSON(...)wrapper from thewebhookinput, but it would have saved me a lot of time if the exception was handled better by thi action.Note, the
err.toJSONin the exception is unrelated to thetoJSONin my input - its only coincidental that we both used (different)toJSONfunctions (JavaScript vs GitHub Expression respectively).Cheers.