harmony icon indicating copy to clipboard operation
harmony copied to clipboard

[Bug] Bot Randomly Crashes

Open Tnology opened this issue 1 year ago • 1 comments

What's the bug? My bot, which uses Harmony, will sometimes crash at random with an "Uncaught DiscordAPIError".

How do we reproduce it? I'm unable to consistently reproduce the error. My bot will randomly crash if I leave it running, and I'm not sure about how it's triggered. The code to my bot is here: https://github.com/Tnology/TnologyDiscordBot

What should have happened? The bot is supposed to function properly and not crash.

What is actually happening? While my bot is running, the bot randomly crashes with an error as seen below:

error: Uncaught DiscordAPIError:
GET /guilds/471700758354460672/members/1017989345292058656 returned 404
(10007) Unknown Member
      throw new DiscordAPIError({
            ^
    at BucketHandler.execute (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/bucket.ts:224:13)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async BucketHandler.push (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/bucket.ts:55:13)
    at async RESTManager.make (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/manager.ts:236:12)
    at async RESTManager.get (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/rest/manager.ts:259:12)
    at async MemberRolesManager._resolveMemberPayload (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/managers/memberRoles.ts:22:23)
    at async MemberRolesManager.array (https://raw.githubusercontent.com/harmonyland/harmony/daca400ae9feab19604381abddbdab16aa1ede2b/src/managers/memberRoles.ts:50:17)
[root@vps TnologyDiscordBot]# 

The bot fully stops as a result of the crash and needs to be restarted.

What versions you're using?

  • OS: Rocky Linux 8.8, Kernel 4.18.0-477.21.1.el8_8.x86_64
  • Deno: Deno 1.38.0
  • Harmony: Harmony Commit daca400ae9feab

Do you have anything to tell us more about the bug? I attempted to use an unhandledrejection event handler, but it doesn't really work in my bot's code. Here is the code that I tried with my bot:

// unhandledrejection.js
globalThis.addEventListener("unhandledrejection", (e) => {
  console.log("unhandled rejection at:", e.promise, "reason:", e.reason);
  e.preventDefault();
});

function Foo() {
  this.bar = Promise.reject(new Error("bar not available"));
}

new Foo();
Promise.reject();

Source: Deno Docs, https://deno.com/blog/v1.24#unhandledrejection-event

Instead, here is the output that I get (trying to run on Windows 11, as I am testing from VS Code):

C:\Users\Tyler\Documents\GitHub\TnologyDiscordBot>deno run -A main.ts
error: Uncaught Error: bar not available
    this.bar = Promise.reject(new Error("bar not available"));
                              ^
    at new Foo (file:///C:/Users/Tyler/Documents/GitHub/TnologyDiscordBot/main.ts:718:31)
    at file:///C:/Users/Tyler/Documents/GitHub/TnologyDiscordBot/main.ts:721:3
    at eventLoopTick (ext:core/01_core.js:183:11)

C:\Users\Tyler\Documents\GitHub\TnologyDiscordBot>

It works in the Deno CLI when I just run deno and paste the code there, but not with my bot. I'm not sure why.

Tnology avatar Nov 10 '23 18:11 Tnology