deno icon indicating copy to clipboard operation
deno copied to clipboard

Error when Network Connection Fails in discord.js on Deno

Open speedfighter opened this issue 1 year ago • 1 comments

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

speedfighter avatar Oct 13 '24 20:10 speedfighter

Same issue here with Deno version 2.0.0 and 2.0.4 image

x1xo avatar Oct 31 '24 22:10 x1xo

Same issue here. It happens randomly after a long period of time.

blaze-developer avatar Nov 05 '24 00:11 blaze-developer

this still seems to be an issue as of version 2.0.5: image

has anyone found a workaround to have deno restart after encountering this error?

colinkautz avatar Nov 08 '24 18:11 colinkautz

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.

littledivy avatar Nov 09 '24 05:11 littledivy

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].

littledivy avatar Nov 09 '24 06:11 littledivy

If @discordjs/[email protected] fixes it, it is up to Discordjs itself to update it as they are still using version 1.1.1.

keybraker avatar Nov 13 '24 17:11 keybraker