Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Successfully merging this pull request may close these issues.

None yet

4 participants