Error listeners

Which listener catches this (image)? I have MessageCommandError and ChatInputCommandError listeners and neither one gets a log, I don't even get anything in the console. In addition, there are also MessageCommandDenied and ChatInputCommandDenied listeners
23 Replies
Favna
Favna2y ago
None. There is no function called expect on Result. What you're writing is a syntax error. And pickResult never throws. That's the whole point of pickResult as opposed to pick.
oriel beck
oriel beckOP2y ago
Interesting, VScode is drunk then, I should check where does this function come from cause it isn't throwing errors for me using it... Any way to make ResultError throw custom errors if it doesn't find what I'm trying to pick/rest?
Favna
Favna2y ago
Use pickResult, check isErr() and throw a custom UserError
oriel beck
oriel beckOP2y ago
Yeah, that's what I suspected, I was just looking for a shorter solution, isn't there something like isErrAnd (I don't remember the Result class by heart)
oriel beck
oriel beckOP2y ago
Thx
oriel beck
oriel beckOP2y ago
So shouldn't that technically work?
Favna
Favna2y ago
oh my bad I forgot that anyway it will still throw a ResultError you need to catch in *CommandError
oriel beck
oriel beckOP2y ago
np, ideas as to why it doesn't actually trigger anything? Like, I debugged it, and it doesn't go past that if the error happens, but, the console stays empty The error isn't passed to the error event at all, other errors do though (like the no subcommands found error the subcommands plugin throws)
Favna
Favna2y ago
is this a subcommand...?
oriel beck
oriel beckOP2y ago
No Actually Yeah
Favna
Favna2y ago
does it extend the subcommand class?
oriel beck
oriel beckOP2y ago
Yeah it is It's a subcommand Is there another event that they throw? Couldn't find anything about that
Favna
Favna2y ago
then you need to use *SubcommandError
oriel beck
oriel beckOP2y ago
For the love of god So many listeners...
Favna
Favna2y ago
shrug
oriel beck
oriel beckOP2y ago
I wish I could just combine the error and deny listeners of everything into one, is that even possible?
Favna
Favna2y ago
No and that would be a code smell if it would be possible because it means you're making 1 thing responsible for multiple completely disparate things subcommands overwrite messageRun and chatInputRun (and you should absolutely never implement those functions when using subcommands) https://github.com/sapphiredev/plugins/blob/main/packages/subcommands/src/lib/Subcommand.ts which is why they throw their own errors, because only uncaught and unexpected errors should end up in the default listeners
oriel beck
oriel beckOP2y ago
Well, I have listeners for chat input, message (and now subcommand) denies and errors, and they all technically do (well, will do, it's wip) the exact same thing Code duplication basically
Favna
Favna2y ago
there is this thing called a module system yaknow
import { handleError } from '../lib/whatever'

// do stuff

return handleError(allTheData)
import { handleError } from '../lib/whatever'

// do stuff

return handleError(allTheData)
oriel beck
oriel beckOP2y ago
Yeah, that's the plan currently The bot is written with functional programming, I'm trying to minimize duplicated code when possible Thx tho, this solves the issue
Want results from more Discord servers?
Add your server