Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#511 2 bình luận 3 reaction 0 người được giao Xem trên GitHub

@saschabuehrle đang làm issue này rồi.

Từ ngày 24/3/2026.

  • #579 của @saschabuehrle — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
github-actions, javascript
Lĩnh vực
ci-cd, devops

Hướng nghiên cứu

Bắt đầu trong src/webhook.js tại khối catch được báo cáo ở dòng 36, sau đó xem lại cách khối này được gọi từ src/send.js và src/index.js. Đảm bảo rằng một URL webhook không hợp lệ báo cáo lỗi nền tảng mà không giả định exception có toJSON; hoàn tất khi lỗi ban đầu được hiển thị thay vì một TypeError thứ cấp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
JavaScript
Star
1.4k
Fork
200
Merge trung bình
1 phút
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của slackapi/slack-github-action

Tất cả issue của slackapi/slack-github-action

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.