`TypeError: err.toJSON is not a function` when webhook URL is invalid
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- github-actions, javascript
Direzione di ricerca
Inizia in src/webhook.js nel blocco catch segnalato alla riga 36, quindi esamina come viene chiamato da src/send.js e src/index.js. Assicurati che un URL webhook non valido riporti l'errore sottostante senza presumere che l'eccezione abbia toJSON; il lavoro è completato quando viene mostrato l'errore originale invece di un TypeError secondario.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- JavaScript
- Stelle
- 1.4k
- Fork
- 200
- Merge medio
- 2h 59m
- PR unite (30g)
- 6
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di slackapi/slack-github-action
-
docs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
slackapi/slack-github-action#667 ·
-
discussion security semver:major
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
slackapi/slack-github-action#621 · 1 commento · 1 reazione ·
-
bug: Unexpected token 'o', "ok" is not valid JSONForse di nuovo libera @zimeg l’ha presa 51 giorni fa e non c’è nessuna pull request aperta. Apertadependencies question
slackapi/slack-github-action#671 · 2 commenti · 1 assegnatario ·
-
needs info question
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
slackapi/slack-github-action#654 · 7 commenti · 5 reazioni ·
-
question
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
slackapi/slack-github-action#520 · 1 commento ·
Tutte le issue di slackapi/slack-github-action
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
keyxmakerx/Chronicle#967 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue hacktoberfest
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
RogueAlg0/taken#386 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
external-issue to-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
LearningCircuit/local-deep-research#7067 ·
I maintainer di solito rispondono entro 1 giorno