slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.72k stars 387 forks source link

Intermittent UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of undefined #2158

Open ankbhar22 opened 2 weeks ago

ankbhar22 commented 2 weeks ago

@slack/bolt 3.12.1

"dependencies": {
    "@pagerduty/pdjs": "^2.2.4",
    "@slack/bolt": "^3.12.1",
    "@slack/web-api": "^6.7.2",
    "axios": "^1.3.3",
    "axios-retry": "^3.6.0",
    "node-cache": "^5.1.2",
    "winston": "^3.8.2"
  },

Intermittently get following error while trying to connect to slack, most of the time code works fine.

socket-mode:SocketModeClient:39 Going to establish a new connection to Slack ...
(node:25) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of undefined
    at SocketModeReceiver.defaultProcessEventErrorHandler [as processEventErrorHandler] (/usr/src/app/node_modules/@slack/bolt/dist/receivers/SocketModeFunctions.js:16:92)
    at SocketModeClient.<anonymous> (/usr/src/app/node_modules/@slack/bolt/dist/receivers/SocketModeReceiver.js:129:50)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:25) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 30)
filmaj commented 2 weeks ago

This issue was fixed almost 2 years ago here: https://github.com/slackapi/bolt-js/pull/1553

I believe the fix (optional chaining on the body event property) was released in bolt-js 3.12.2. Please upgrade to a slightly newer version to at least prevent the crash.