`TypeError: err.toJSON is not a function` when webhook URL is invalid
Đá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
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ả
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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của slackapi/slack-github-action
-
docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
slackapi/slack-github-action#667 ·
-
discussion security semver:major
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
slackapi/slack-github-action#621 · 1 bình luận · 1 reaction ·
-
bug: Unexpected token 'o', "ok" is not valid JSONCó thể làm lại được @zimeg đã nhận 54 ngày trước và không có pull request nào đang mở. Đang mởdependencies question
slackapi/slack-github-action#671 · 2 bình luận · 1 người được giao ·
-
needs info question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
slackapi/slack-github-action#654 · 7 bình luận · 5 reaction ·
-
question
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
slackapi/slack-github-action#520 · 1 bình luận ·
Tất cả issue của slackapi/slack-github-action
Issue tương tự
-
[Feature]:Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Uuriko/project-room#1554 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
automated issue report
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
lirantal/discoprint#36 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
accepting PR Content:HTML
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
mdn/content#45988 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pnpm/pnpm#16635 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày