rust-lang / discord-mods-bot

discord moderation bot
MIT License
71 stars 30 forks source link

Send error message on command fail #17

Open khionu opened 4 years ago

khionu commented 4 years ago

If a command encounters a non-fatal error, it should send the error as a response. Note, an invalid command should not be treated as an error.

kangalio commented 3 years ago

Pulling this through would also simplify error handling situations like these

https://github.com/rust-lang/discord-mods-bot/blob/e4c0bfd6b9c881c667f36d5dc72bb7fdf8fd7ed9/src/crates.rs#L46-L62

Right now, the code handles errors in two different ways simultaneously: some kinds of errors (e.g. network errors) are propagated up the chain and not posted, and other errors (crate not found) are posted. By having all errors be printed by default, the error propagation operator could be used for both:

let krate = get_crate(&args)?;
args.msg.channel_id.send_message(&args.cx, |m| {
    m.embed(|e| {
        e.title(&krate.name)
            .url(format!("https://crates.io/crates/{}", krate.id))
            .description(&krate.description)
            .field("version", &krate.version, true)
            .field("downloads", &krate.downloads, true)
            .timestamp(krate.updated.as_str())
    });

    m
})?;
khionu commented 3 years ago

"Crate not found" is not an error, from our perspective. It's expected behaviour for command invocations to provide invalid input. The idea behind this issue is that unexpected errors would provide some feedback to the user instead of the bot being silent, so we should have a case in the central command handler for sending a generic "an error occurred, please contact..." message