Error when Network Connection Fails in discord.js on Deno
When the network connection encounters an error, I receive the following error from discord.js
Uncaught TypeError: Cannot use 'in' operator to search for 'code' in undefined
at WebSocketShard.onError (file:///C:/Users/fabia/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:1065:16)
at WebSocket.connection.onerror (file:///C:/Users/fabia/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:683:12)
at WebSocket.wrappedHandler (ext:deno_web/02_event.js:1400:12)
at innerInvokeEventListeners (ext:deno_web/02_event.js:757:7)
at invokeEventListeners (ext:deno_web/02_event.js:804:5)
at dispatch (ext:deno_web/02_event.js:661:9)
at WebSocket.dispatchEvent (ext:deno_web/02_event.js:1041:12)
at WebSocket.[[[eventLoop]]] (ext:deno_websocket/01_websocket.js:494:16)
at eventLoopTick (ext:core/01_core.js:175:7)
However, when I test the same code with Node.js, this error does not occur. According to the discord.js github (Github discord.js Issue), the issue seems to be related to Deno.
Version: Deno 2.0.0
Same issue here with Deno version 2.0.0 and 2.0.4
Same issue here. It happens randomly after a long period of time.
this still seems to be an issue as of version 2.0.5:
has anyone found a workaround to have deno restart after encountering this error?
So according to the spec, ErrorEvent's error attribute may not be initialized. Discord.js should handle the case where event.error is not initialized.
https://html.spec.whatwg.org/multipage/webappapis.html#errorevent
The error attribute must return the value it was initialized to. It must initially be initialized to undefined. Where appropriate, it is set to the object representing the error (e.g., the exception object in the case of an uncaught exception).
We can fix this on Deno's side too by initializing with an error.
It looks like the discordjs has removed the event.error checks in recent versions. https://github.com/discordjs/discord.js/commit/a6de2707fc1107262b12491f73b5b6887df91c67
This issue should be fixed with @discord/[email protected].
If @discordjs/[email protected] fixes it, it is up to Discordjs itself to update it as they are still using version 1.1.1.