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:
Very low, this is the only time this ever happened.
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.
Most helpful comment
I honestly thought I was reporting a bug.