Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fixing ReferenceError in catch block #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

C-Doug-iS
Copy link

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.

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.
@@ -109,7 +109,7 @@ client.on("messageCreate", async (message) => {
message.channel.send(`\`\`\`js\n${cleaned}\n\`\`\``);
} catch (err) {
// Reply in the channel with our error
message.channel.send(`\`ERROR\` \`\`\`xl\n${cleaned}\n\`\`\``);
message.channel.send(`\`ERROR\` \`\`\`xl\n${err.stack}\n\`\`\``);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This doesn't send the actual error.
  2. err.stack is string[]? meaning it could be undefined.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This doesn't send the actual error.
  2. err.stack is string[]? meaning it could be undefined.
  1. Error#stack does send the actual error message, plus the error stack.
  2. Technically err is of type unknown, so an instance check for Error would be appropriate here, but the chances of a non-error type being thrown is unlikely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RealShadowNova... oops; implementation issue with the way my stack system works. soz!

@thetayloredman
Copy link
Contributor

can you screenshot what actually happens?

@C-Doug-iS
Copy link
Author

            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.

Copy link
Contributor

@thetayloredman thetayloredman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be merged lmao

@migue802
Copy link

Bump - why this isn't merged yet

@Chicken
Copy link

Chicken commented Aug 25, 2024

Because the guide, the bot, and the community are pretty much dead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants