Discord.js: Uncaught Promise Error in Request Handler

Created on 7 Jul 2017  Â·  14Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
When a Promise gets rejected due to a Discord API Error (let's say Missing Permissions), I'm logging an Uncaught Promise Error for the error, additionally to that, my catch handler on all discord.js promises, logs the same error too.

Log:

1|CharuruD | error: 2017/07/07, 22:04:19.966@ Caught Error: { DiscordAPIError: Missing Permissions
1|CharuruD |     at item.request.gen.end (/var/opt/Discord_Bot/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:69:65)
1|CharuruD |     at then (/var/opt/Discord_Bot/node_modules/snekfetch/src/index.js:243:21)
1|CharuruD |     at <anonymous>
1|CharuruD |     at process._tickCallback (internal/process/next_tick.js:169:7)
1|CharuruD |   name: 'DiscordAPIError',
1|CharuruD |   message: 'Missing Permissions',
1|CharuruD |   code: 50013 }
1|CharuruD | error: 2017/07/07, 22:04:19.970@ Uncaught Promise Error: DiscordAPIError: Missing Permissions
1|CharuruD |     at item.request.gen.end (/var/opt/Discord_Bot/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:69:65)
1|CharuruD |     at then (/var/opt/Discord_Bot/node_modules/snekfetch/src/index.js:243:21)
1|CharuruD |     at <anonymous>

Include a reproducible code sample here, if possible:
In my case a send method with a file upload.

message.channel.send({ files: [ botBasepath+'/assets/profile/level.png' ] }).catch(this.client.errorConsole);

Further details:

  • discord.js version: v11.2 (11.1-dev branch)
  • node.js version: v8.1.3
  • Operating system: Debian Jessie x64
  • Priority this issue should have – please be realistic and elaborate if possible: High, since leaking error.
medium error handling bug

All 14 comments

Is this still happening?

Yes, this is still happening.

error: 2017/08/17, 18:57:04.502@ Uncaught Promise Error: DiscordAPIError: Missing Access
    at item.request.gen.end (/var/opt/Discord_Bot/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:68:65)
    at then (/var/opt/Discord_Bot/node_modules/snekfetch/src/index.js:243:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
error: 2017/08/17, 18:58:03.988@ Uncaught Promise Error: DiscordAPIError: Missing Access
    at item.request.gen.end (/var/opt/Discord_Bot/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:68:65)
    at then (/var/opt/Discord_Bot/node_modules/snekfetch/src/index.js:243:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
error: 2017/08/17, 18:58:09.793@ Uncaught Promise Error: DiscordAPIError: Missing Access
    at item.request.gen.end (/var/opt/Discord_Bot/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:68:65)
    at then (/var/opt/Discord_Bot/node_modules/snekfetch/src/index.js:243:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
error: 2017/08/17, 19:04:12.575@ Uncaught Promise Error: DiscordAPIError: Missing Access
    at item.request.gen.end (/var/opt/Discord_Bot/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:68:65)
    at then (/var/opt/Discord_Bot/node_modules/snekfetch/src/index.js:243:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Stuff like that (good job at JS for that useful stack trace).

How can I reproduce this? Sending a file without the permission to send a message? Or without the permission to send a file?

I'm pretty sure that error was because of missing attach files permissions.
I'm going to adapt my d.js fork that way that it will capture stack trace before it goes into next process tick and attach it to the error stack trace if there is an error. Hopefully I will get more useful information.

If you could also provide a perfect way to reproduce this, I would greatly appreciate it (this includes permissions/overwrites n stuff).

I can reproduce it with a simple command that just sends a file, nothing else, all it does is send a file. The only permissions overwrite that denies anything is ATTACH_FILES, everything else is on allow (like the role permissions, excluding administrator, create invite).

module.exports = class TestCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'test',
            aliases: [ ],
            group: 'fun',
            memberName: 'test',
            description: 'The test.',
            guildOnly: false,
            throttling: {
                usages: 1,
                duration: 10
            }
        });
    }

    async run(message) {
        return message.say('', { files: [ botBasepath+'/thefile.jpg' ] });
    }
};

In the console I get that:

error: 2017/08/21, 00:46:41.706@ Uncaught Promise Error: DiscordAPIError: Missing Permissions
    at item.request.gen.end (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\rest\R
equestHandlers\Sequential.js:70:66)
    at then (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\snekfetch\src\index.js:243:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)
Error
    at new APIRequest (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\rest\APIRequ
est.js:15:30)
    at RESTManager.makeRequest (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\res
t\RESTManager.js:46:24)
    at send (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\rest\RESTMethods.js:11
3:21)
    at Promise (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\rest\RESTMethods.js
:120:12)
    at Promise (<anonymous>)
    at RESTMethods.sendMessage (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\res
t\RESTMethods.js:59:12)
    at Promise.all.then.files (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\structures\
interfaces\TextBasedChannel.js:111:49)
    at <anonymous>

Can you see if this is an issue in v12.0.0-dev? There was a rewrite of the ratelimiter which is where your error says it's coming from.

Just installed master for d.js and commando. Still the same issue.

error: 2017/08/21, 01:03:00.978@ Uncaught Promise Error: DiscordAPIError: Missing Permissions
    at item.request.gen.end (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\discord.js\src\client\rest\
andlers\RequestHandler.js:52:65)
    at then (Z:\Eigene Dokumente\Discord Bots\Charuru Commando\node_modules\snekfetch\src\index.js:243:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

I did it like 20 times or so:

Always getting the same response.

But what's with the console?

What you would expect

Tested with both, a command that has async run and sending a file and a command that does have run sending a file, no uncaught promises.

Hm, funny thing is that it seems to be an issue before the commando PR Uncaught Commando Promise Error (https://github.com/Gawdl3y/discord.js-commando/pull/52). If I await the command promise directly, the issue is gone. I think we can close this issue.

Have you solved this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iCrawl picture iCrawl  Â·  3Comments

Blumlaut picture Blumlaut  Â·  3Comments

ghost picture ghost  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

Lombra picture Lombra  Â·  3Comments