Discord.js: Unhandled exception after websocket connection failure

Created on 28 Jul 2018  Â·  5Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:

While running my bot, I got an unhandled exception error due to a websocket connection failure. I'm not sure exactly where the error is, but I feel that it might be possible to handle it in some way and retry making the connection?

Include a reproducible code sample here, if possible:

Here's the exception. I started my bot at 21:44. At 01:17 the next morning it crashed:

events.js:173
    throw err; // Unhandled 'error' event
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
    at Client.emit (events.js:171:17)
    at Client.EventEmitter.emit (domain.js:442:20)
    at WebSocketConnection.onError (/Users/msikma/Projects/callisto-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
    at WebSocket.onError (/Users/msikma/Projects/callisto-bot/node_modules/ws/lib/event-target.js:128:16)
    at WebSocket.emit (events.js:182:13)
    at WebSocket.EventEmitter.emit (domain.js:442:20)
    at _receiver.cleanup (/Users/msikma/Projects/callisto-bot/node_modules/ws/lib/websocket.js:211:14)
    at Receiver.cleanup (/Users/msikma/Projects/callisto-bot/node_modules/ws/lib/receiver.js:557:13)
    at WebSocket.finalize (/Users/msikma/Projects/callisto-bot/node_modules/ws/lib/websocket.js:206:20)
    at TLSSocket.emit (events.js:182:13)
    at TLSSocket.EventEmitter.emit (domain.js:442:20)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

All my bot does with Discord is send messages (text and RichEmbed) to channels. I don't make use of any other features.

I'm now adding a handler for uncaught exceptions to my bot's code. Not much information about the error unfortunately (since it ended up printing [object Object]) but if it ever happens again I'll have more.

Actually I'm not entirely sure if I should add a handler for all exceptions to catch issues like this, and maybe restarting is better?

Apologies for the low amount of information in my bug report. I hope it's useful anyway.

Further details:

  • discord.js version: 11.3.2
  • node.js version: v10.7.0
  • Operating system: Mac OS X High Sierra 10.13.6
  • Priority this issue should have – please be realistic and elaborate if possible:

Very low, this is the only time this ever happened.

  • [x] I found this issue while running code on a __user account__
  • [ ] I have also tested the issue on latest master, commit hash:
question (please use Discord instead)

Most helpful comment

I honestly thought I was reporting a bug.

All 5 comments

The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.

You should try listening for error events from the client

@hydrabolt thanks.

I'm guessing that I did something wrong in not listening to some error event. I would not have been able to guess that from @Dev-Yukine's response or from the error log.

Next time please just use the Server for questions.

I honestly thought I was reporting a bug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  Â·  3Comments

kvn1351 picture kvn1351  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

BrandonCookeDev picture BrandonCookeDev  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments