Comments (6)
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
from glommio.
I personally think a good pattern for a library like this could involve using thiserror
from dtolnay that makes creating ergonomic, library errors much easier. Basically it lets us define one error type for this library (so that users of this library can work with a single type) and multiple enum variants for all the different error cases. It also makes it easier to encapsulate the source
error inside of a particular variant (so the user can introspect what the actual cause of the error was). The thing that thiserror
gives, is easy From/display implementations based on a proc macro.
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),
}
from glommio.
hello @bryandmc
That looks great to me. My main concern is that I'd like to make sure that this interops well with io::Error
, because that is everywhere : one good example is the Async I/O traits.
That means not only being able to convert, but keeping meaningful messages and causes whenever possible.
In other words, something that resembles a "Bad File" in Glommio should translate to "Bad File" in io::Error
, and not just going the lazy route of marshalling everything under Custom
from glommio.
@glommer That shouldn't be a problem. It can preserve and entire chain of "source" errors. Meaning it can hold the io::Error
that caused the error in the first place, along with other information. I'll take a look at the current code base and see how it'll fit in. That said, I think we can accomplish your goals with this pretty easily.
from glommio.
our goals!!
I am more concerned about others that aren't originally io::Error
. See for example the ones in sync::rwlock
from glommio.
Bryan handled this one - #227
from glommio.
Related Issues (20)
- Is it possible to include my project (dbeel) in the readme?
- Ordering of `ReadManyResult ` HOT 2
- process gets stuck in D state if there is a big read (about 6 MB) HOT 4
- Document what happens on non-Linux+io-uring-support HOT 3
- RawTask memory leak HOT 5
- `Directory::open` fails consistently where `std::fs::` succeeds
- Support for sending raw Ethernet frames HOT 3
- this is no core_cpus_list file, how to fix it?
- What's the problem with performance, implementation or usage? HOT 6
- Is it possible to make a release? HOT 3
- Harden read buffer pool HOT 2
- RFC: A Send safe `DmaFile` to let the fd be shared across threads
- Valgrind complains about uninitialized memory in buffer returned by read_at_aligned
- Statx is invoked on path instead of fd
- RFC: 0-copy support for writing reads HOT 2
- Can't build an application that using Glommio HOT 5
- Timer adds a surprising amount of delay vs thread::sleep HOT 3
- Timer documentation says confusing things about the task queue HOT 4
- Any interest in adding advisory lock support?
- Implement `Send + Sync` for `ReadResult` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glommio.