oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.22k stars 2.58k forks source link

TypeError: error is not an Object. (evaluating '"code" in error') in discord SDK when error happens #9141

Open capaj opened 4 months ago

capaj commented 4 months ago

What version of Bun is running?

1.0.29+a146856d1

What platform is your computer?

Ubuntu

What steps can reproduce the bug?

use official discord sdk and get an error I use it like this:

import { Client, GatewayIntentBits } from 'discord.js'

 const discordClient = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ]
})

discordClient.login(process.env.DISCORD_TOKEN)

What is the expected behavior?

error handling works inside the SDK

What do you see instead?

1043 |         break;
1044 |       }
1045 |     }
1046 |   }
1047 |   onError(error) {
1048 |     if ("code" in error && ["ECONNRESET", "ECONNREFUSED"].includes(error.code)) {
               ^
TypeError: error is not an Object. (evaluating '"code" in error')
      at onError (/home/capaj/work-repos/brain-crypto-bot/node_modules/.pnpm/@discordjs+ws@1.0.2/node_modules/@discordjs/ws/dist/index.js:1048:9)
      at /home/capaj/work-repos/brain-crypto-bot/node_modules/.pnpm/@discordjs+ws@1.0.2/node_modules/@discordjs/ws/dist/index.js:673:7

Additional information

I have the codebase in private github repo and will gladly share it with anyone from bun team.

Electroid commented 4 months ago

Is there a more specific code example? I'm unable to reproduce this.

hippietrail commented 3 weeks ago

I hit this all the time with my discord bot on macOS Sonoma. I wrote my bot as a learning exercise for TypeScript, Discord, Websocket stuff. It's not really intended for anybody else to use but it is on GitHub: https://github.com/hippietrail/hippiebot.js Just run under node and disconnect from the WiFi and it'll soon crash like in the report. Under nodeJS it will wait for the network to come back.