Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws throws TypeError: Cannot use 'in' operator to search for 'code' in undefined when with Deno #10327

Closed
NeuroWhAI opened this issue Jun 6, 2024 · 6 comments

Comments

@NeuroWhAI
Copy link

NeuroWhAI commented Jun 6, 2024

Which package is this bug report for?

ws

Issue description

  1. Use deno, Make a simple Discord bot.
  2. Leave the bot running for a long time. (Maybe 1 day?)
  3. The bot suddenly throws an error and dies.

Error : TypeError: Cannot use 'in' operator to search for 'code' in undefined
Location: https://github.com/discordjs/discord.js/blob/main/packages/ws/src/ws/WebSocketShard.ts#L794

If I manually modify the conditional statement locally as follows, the problem no longer occurs.
But I'm not sure if it's okay to do this.

onError(error) {
  if (error && "code" in error && ["ECONNRESET", "ECONNREFUSED"].includes(error.code)) {

I'm not sure if this is due to differences between Deno and Node.js, but I suspect it is.

Code sample

No response

Versions

  • discord.js 14.15.3
  • Deno 1.44.0

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMessages, MessageContent

I have tested this issue on a development release

No response

@NeuroWhAI NeuroWhAI changed the title ws throws the error TypeError: Cannot use 'in' operator to search for 'code' in undefined ws throws the error TypeError: Cannot use 'in' operator to search for 'code' in undefined when with Deno Jun 6, 2024
@NeuroWhAI NeuroWhAI changed the title ws throws the error TypeError: Cannot use 'in' operator to search for 'code' in undefined when with Deno ws throws TypeError: Cannot use 'in' operator to search for 'code' in undefined when with Deno Jun 6, 2024
@didinele
Copy link
Member

didinele commented Jun 6, 2024

Hi. Do you have a full stack trace? I'd like to see what invoked onError

@NeuroWhAI
Copy link
Author

I will reproduce and get the trace log.

@NeuroWhAI
Copy link
Author

Here is a trace log. @didinele

error: Uncaught TypeError: Cannot use 'in' operator to search for 'code' in undefined
    at WebSocketShard.onError (file:///C:/Users/neurobox/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:1065:16)
    at WebSocket.connection.onerror (file:///C:/Users/neurobox/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:1401:12)
    at innerInvokeEventListeners (ext:deno_web/02_event.js:754:7)
    at invokeEventListeners (ext:deno_web/02_event.js:801:5)
    at dispatch (ext:deno_web/02_event.js:658:9)
    at WebSocket.dispatchEvent (ext:deno_web/02_event.js:1043:12)
    at WebSocket.[[[eventLoop]]] (ext:deno_websocket/01_websocket.js:471:16)
    at eventLoopTick (ext:core/01_core.js:168:7)

@Jiralite
Copy link
Member

Jiralite commented Jun 7, 2024

If possible, would you be able to log event here so we can see what the payload is?

this.onError(event.error);

@NeuroWhAI
Copy link
Author

NeuroWhAI commented Jun 9, 2024

@Jiralite It was {}... 🤔

    connection.onerror = (event) => {
      console.log("=======================================");
      console.log(JSON.stringify(event));
      console.log("=======================================");
      this.onError(event.error);
    };
=======================================
{}
=======================================

@didinele
Copy link
Member

didinele commented Jun 9, 2024

That's most certainly a deno bug of some sort then, recommend reporting it.

@didinele didinele closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants