Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send error message on command fail #17

Open
khionu opened this issue Mar 6, 2020 · 2 comments
Open

Send error message on command fail #17

khionu opened this issue Mar 6, 2020 · 2 comments

Comments

@khionu
Copy link
Member

khionu commented Mar 6, 2020

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
Copy link

Pulling this through would also simplify error handling situations like these

if let Some(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
})?;
} else {
let message = "No crates found.";
api::send_reply(&args, message)?;
}

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
Copy link
Member Author

khionu commented Jan 31, 2021

"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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants