-
Notifications
You must be signed in to change notification settings - Fork 164
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
Implement error system similar too the approach implemented in io::Error structure #180
Comments
Interesting reading in the context of this issue https://blog.rust-lang.org/inside-rust/2020/11/23/What-the-error-handling-project-group-is-working-on.html |
I personally think a good pattern for a library like this could involve using This seems to be the most idiomatic way to create library errors at the moment. I can provide an example of what this looks like, if anyone is interested. I actually used to use a hacky declarative macro to do basically the same thing before finding this crate, so this doesn't involve some sort of custom dynamic error type or anything like that. It's just an enum at the end of the day with some generated impl's. Thoughts? It's pretty easy to implement and I'd be happy to mock up an example using whatever errors we currently have as the starting point. EDIT: here's an example of what the enum looks like with the macro #[derive(thiserror::Error, Debug)]
pub enum QuicProtoError {
#[error("socket bind error")]
BindError(#[from] io::Error),
#[error("error with quinn endpoint")]
EndpointError(#[from] quinn::EndpointError),
#[error("error setting udp socket options")]
UdpSetupError(#[from] udp::UdpSocketError),
#[error("error configuring TLS")]
TlsConfigurationError(#[from] rustls::TLSError),
#[error("error parsing certificate data")]
CertificateParsingError(#[from] quinn::ParseError),
#[error("error creating quic config")]
QuicConfigError(#[from] anyhow::Error),
#[error("QUIC connection error")]
ConnectionError(#[from] quinn::ConnectionError),
#[error("error connecting to backend - bad parameters provided.")]
BadConnectionParameters(#[from] quinn::ConnectError),
} |
hello @bryandmc That looks great to me. My main concern is that I'd like to make sure that this interops well with That means not only being able to convert, but keeping meaningful messages and causes whenever possible. |
@glommer That shouldn't be a problem. It can preserve and entire chain of "source" errors. Meaning it can hold the |
our goals!! I am more concerned about others that aren't originally |
Uses 'thiserror' and some refactoring to implement a cohesive error type that can encompass all errors produced by glommio. Includes all the natural traits like from/into so try ('?') should work as expected if you are using it on the inner type of whichever variant you are using. Also included in this commit is an example migration of the semaphore errors as an example of how it would likely work. Assuming this is satisfactory, the rest of the errors can be refactored to use this as well. This means we shouldn't need to piggyback on the std::io::Error to express our intent. It should still be used as the inner type if underlying libraries produce this, but otherwise the correct variant of GlommioError should just be manually constructed.
Addresses #180: Implement error system
Bryan handled this one - #227 |
This issue was discussed in community chat. Main issues with io::Error are:
Despite the visible simplicity of the task, it requires deep investigation of current implementations of error handling in Rust and a good understanding of a possible set of errors which could happen (will happen) inside of the library.
The text was updated successfully, but these errors were encountered: