aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
533 stars 98 forks source link

How do I produce meaningful error messages? #234

Open flisk opened 3 years ago

flisk commented 3 years ago

First off, thank you very much for your work on this crate. I've had a lot of fun maintaining my IRC bot written against this library for over a year now.

I'm a little confused about how I can produce meaningful user-facing error messages with 0.15.0. Unfortunately the examples don't seem to shed any light on this.

My application performs reconnect attempts in a loop and reports errors by log, so I'd like to catch any type of error in that loop, report it to the user, and proceed to reconnect. I'm able to obtain an irc::error::Error from the failure::Errors falling out of client.identify(), stream.next() and so on, but simply .to_string()'ing or printing these errors produces very vague results. For example:

an io error occurred

Debug-formatting produces more useful but less user-friendly output:

Io(Custom { kind: Uncategorized, error: "failed to lookup address information: Name or service not known" })

I've taken a look at error.rs. Is my application supposed to match and implement specific behavior for every error type, or is the vagueness of these error messages unintended?

I'd appreciate any pointers.

WhyNotHugo commented 1 year ago

You probably want to render the nested error here:

https://docs.rs/irc/0.15.0/src/irc/error.rs.html#19-102

The API for this is the second example:

https://docs.rs/thiserror/latest/thiserror/#example

I'm not a maintainer here, but a PR patching this sounds pretty reasonable.