discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

Uncaught Promise Error in Request Handler #1666

Closed ghost closed 7 years ago

ghost commented 7 years ago

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:

iCrawl commented 7 years ago

Is this still happening?

ghost commented 7 years ago

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

iCrawl commented 7 years ago

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

ghost commented 7 years ago

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.

iCrawl commented 7 years ago

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

ghost commented 7 years ago

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>
bdistin commented 7 years ago

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.

ghost commented 7 years ago

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)
iCrawl commented 7 years ago

I did it like 20 times or so:

Always getting the same response.

ghost commented 7 years ago

But what's with the console?

iCrawl commented 7 years ago

What you would expect

iCrawl commented 7 years ago

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.

ghost commented 7 years ago

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.

chanjungkim commented 5 years ago

Have you solved this issue?