#Catching errors globally so my bot doesn't crash

8 messages · Page 1 of 1 (latest)

muted pollen
#

how do I catch all errors globally so that my bot doesn't crash when it for some reason or another errors? For example, if I try to edit an interaction which is unknown my bot will go offline... I don't want to have to .catch every time I try to edit an interaction.

stuck yewBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

brittle aurora
#

this will keep it from crashing when an error occurs

muted pollen
#

Thank you 🙂

tight mesa
#

I don't want to have to .catch every time I try to edit an interaction.

you really should, though
giving the user meaningful error feedback in context of what they are trying to do at the time is always preferable to a generic handler that just let's it propagate to the main scope and then throws "oopsies"

muted pollen
#

While I do agree with you that generic handlers are not as good, it seems like it will just make everything very messy and hard to read if I am adding .catch to everything, and try/catch isn't very elegant either. Maybe I can consider it once everything has been made.

tight mesa
#

well, why are you writing code?
so the user has something that's a nice experience in usage
or so you can frame it at a wall and go "oh that's pretty"

context-aware errors are def. an improvement in user experience
and try/catch wrapping scopes is not all that terrible looking either
i've just learned that code should be maintainable and understandable vs. impressive and pretty to look at.
every time you move an error presentation outside the scope it is actually coming from it's harder to trace where it's from and/or remember that it happens elsewhere anyways

at the end of the day: you do you firY