Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#511 コメント 2 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
github-actions, javascript
領域
ci-cd, devops

調査の方向性

src/webhook.js の 36 行目で報告されている catch ブロックから始め、次に src/send.js と src/index.js からどのように呼び出されているかを確認します。無効な webhook URL が、例外に toJSON があると仮定せずに根本のエラーを報告するようにします。完了条件は、二次的な TypeError ではなく元の失敗が表示されることです。

索引モデルが issue の本文から書いたものです。

説明

bug

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.

主要言語
JavaScript
スター
1.4k
フォーク
200
平均マージ
2時間 59分
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

slackapi/slack-github-action のほかの issue

slackapi/slack-github-action の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。