Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#511 2 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
github-actions, javascript
Área
ci-cd, devops

Línea de trabajo

Comienza en src/webhook.js, en el bloque catch indicado en la línea 36, y revisa después cómo se llama desde src/send.js y src/index.js. Asegúrate de que una URL de webhook no válida informe del error subyacente sin asumir que la excepción tiene toJSON; se considera terminado cuando se muestra el fallo original en lugar de un TypeError secundario.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
JavaScript
Estrellas
1.4k
Forks
200
Merge medio
2 h 59 min
PR fusionados (30 d)
6

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de slackapi/slack-github-action

Todos los issues de slackapi/slack-github-action

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.