discord-mods-bot icon indicating copy to clipboard operation
discord-mods-bot copied to clipboard

Send error message on command fail

Open khionu opened this issue 5 years ago • 2 comments

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.

khionu avatar Mar 06 '20 09:03 khionu

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
})?;

kangalio avatar Jan 29 '21 10:01 kangalio

"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

khionu avatar Jan 31 '21 18:01 khionu