discordjs-bot-guide icon indicating copy to clipboard operation
discordjs-bot-guide copied to clipboard

Fixing ReferenceError in catch block

Open C-Doug-iS opened this issue 3 years ago • 4 comments

Sending error to channel results in a ReferenceError because cleaned is not defined in the catch block's scope.

Replaced with sending the error's stack to resolve this.

C-Doug-iS avatar Apr 26 '22 15:04 C-Doug-iS

can you screenshot what actually happens?

thetayloredman avatar Apr 27 '22 02:04 thetayloredman

            message.channel.send(`\`ERROR\` \`\`\`xl\n${cleaned}\n\`\`\``);
                                                        ^

ReferenceError: cleaned is not defined

As cleaned is not defined in the catch block, a ReferenceError is thrown. Error#stack lazily generates a string, which to the best of my knowledge should always be populated once accessed.

You could always just send the plain Error, but that will not provide any information regarding the actual location of the error, just the type and message associated with it.

C-Doug-iS avatar Apr 27 '22 03:04 C-Doug-iS