serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
653 stars 114 forks source link

`FrameworkError::ctx` returns `None` for many variants #295

Closed mammothbane closed 2 months ago

mammothbane commented 2 months ago

Currently FrameworkError::ctx has the following match case, despite the fact that some of these variants have an associated ctx:

pub fn ctx(&self) -> Option<crate::Context<'a, U, E>> {
    Some(match *self {
            // ...
            Self::Setup { .. }
            | Self::EventHandler { .. }
            | Self::UnknownCommand { .. }
            | Self::UnknownInteraction { .. }
            | Self::NonCommandMessage { .. }
            | Self::DynamicPrefix { .. } => return None,
    })
}

This was unexpected — Is there a reason?

My on_error handler looks like:

if let Some(ctx) = err.ctx() {
    // notify the user something has gone wrong
    // presence of ctx suggests the error arose in response to a comamnd
} else {
    // no message context available, can't/not appropriate to notify user
    warn!("error had no context!");
}
GnomedDev commented 2 months ago

Their ctx is not a poise::Context, it is a serenity::client::Context.

mammothbane commented 2 months ago

Whoops, just realized it's not all of them — however, several of them do have one, e.g. UnknownInteraction, UnknownCommand, which are what I need

mammothbane commented 2 months ago

Oh, nvm, understood — what I'm looking at is the framework context. Sorry for live-rubber-ducking this.