`TypeError: err.toJSON is not a function` when webhook URL is invalid
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- github-actions, javascript
Research direction
Start in src/webhook.js at the catch block reported at line 36, then review how it is called from src/send.js and src/index.js. Ensure an invalid webhook URL reports the underlying error without assuming the exception has toJSON; done means the original failure is shown instead of a secondary TypeError.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- JavaScript
- Stars
- 1.3k
- Forks
- 200
- Avg merge
- 2h 59m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from slackapi/slack-github-action
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 82/100
slackapi/slack-github-action#667 ·
-
discussion security semver:major
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
slackapi/slack-github-action#621 · 1 comment · 1 reaction ·
-
dependencies question
slackapi/slack-github-action#671 · 2 comments · 1 assignee ·
-
needs info question
Difficulty 3/5 1-2 days Newbie friendliness 55/100
slackapi/slack-github-action#654 · 7 comments · 5 reactions ·
-
question
Difficulty 5/5 Over a week Newbie friendliness 20/100
slackapi/slack-github-action#520 · 1 comment ·
All issues in slackapi/slack-github-action
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Browser Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
getsentry/sentry-javascript#24577 · 1 comment ·
-
curation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
amponce/archive-movie-browser#186 ·
-
light
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
aemdemos/patients-stryker#253 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
clerk/javascript#9852 ·