tbeeck / lichess-discord

Discord bot for lichess
GNU General Public License v3.0
4 stars 2 forks source link

Gracefully exit on exception so systemd service may restart #2

Closed ddugovic closed 6 years ago

ddugovic commented 6 years ago

Last weekend an exception occurred which disconnected the bot from Discord but left the process running.

This patch terminates the process so my systemd service may restart the bot in the rare circumstance that an exception occurs.

tbeeck commented 6 years ago

Thanks for catching this. Any info on the exception that occurred?

ddugovic commented 6 years ago

Only one of these seems to make any sense, I'm afraid. Maybe Discord itself has problems too, idk:

Sep 20 14:25:40 vps178028 node[25759]: Bot is online!
Sep 20 14:25:40 vps178028 node[25759]: 13356 users, in 2 servers connected.
Sep 20 14:26:02 vps178028 node[25759]: Uncaught Exception:  Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
Sep 20 14:26:02 vps178028 node[25759]:     at Client.emit (events.js:171:17)
Sep 20 14:26:02 vps178028 node[25759]:     at WebSocketConnection.onError (./node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
Sep 20 14:26:02 vps178028 node[25759]:     at WebSocket.onError (./node_modules/ws/lib/event-target.js:128:16)
Sep 20 14:26:02 vps178028 node[25759]:     at WebSocket.emit (events.js:182:13)
Sep 20 14:26:02 vps178028 node[25759]:     at _receiver.cleanup (./node_modules/ws/lib/websocket.js:211:14)
Sep 20 14:26:02 vps178028 node[25759]:     at Receiver.cleanup (./node_modules/ws/lib/receiver.js:557:13)
Sep 20 14:26:02 vps178028 node[25759]:     at WebSocket.finalize (./node_modules/ws/lib/websocket.js:206:20)
Sep 20 14:26:02 vps178028 node[25759]:     at TLSSocket.emit (events.js:182:13)
Sep 20 14:26:02 vps178028 node[25759]:     at emitErrorNT (internal/streams/destroy.js:82:8)
Sep 20 14:26:02 vps178028 node[25759]:     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
Sep 20 14:26:02 vps178028 node[25759]:     at process._tickCallback (internal/process/next_tick.js:63:19)
Sep 20 14:26:02 vps178028 systemd[1]: lichess-discord.service: Main process exited, code=exited, status=1/FAILURE
Sep 21 08:06:34 vps178028 node[9734]: treating !he;[ from <@99742488666845184>(Ovyerus) as command
Sep 21 08:06:35 vps178028 node[9734]: treating !help from <@99742488666845184>(Ovyerus) as command
Sep 21 08:06:35 vps178028 node[9734]: Uncaught Promise Error:  { DiscordAPIError: Cannot send messages to this user
Sep 21 08:06:35 vps178028 node[9734]:     at item.request.gen.end (/home/lichess/lichess-discord/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:79:15)
Sep 21 08:06:35 vps178028 node[9734]:     at then (/home/lichess/lichess-discord/node_modules/snekfetch/src/index.js:215:21)
Sep 21 08:06:35 vps178028 node[9734]:     at process._tickCallback (internal/process/next_tick.js:68:7)
Sep 21 08:06:35 vps178028 node[9734]:   name: 'DiscordAPIError',
Sep 21 08:06:35 vps178028 node[9734]:   message: 'Cannot send messages to this user',
Sep 21 08:06:35 vps178028 node[9734]:   path: '/api/v7/channels/492285548354863106/messages',
Sep 21 08:06:35 vps178028 node[9734]:   code: 50007,
Sep 21 08:06:35 vps178028 node[9734]:   method: 'POST' }
Sep 21 08:06:35 vps178028 systemd[1]: lichess-discord.service: Main process exited, code=exited, status=1/FAILURE
tbeeck commented 6 years ago

Yep a little beyond my comprehension. Glad to see the bot is serving so many :)

Perhaps this is worth checking out for the 'cannot send messages to this user' error. https://github.com/LakeYS/Discord-Trivia-Bot/issues/21