-
Notifications
You must be signed in to change notification settings - Fork 15
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
Use thiserror Errors instead of relying on anyhow #13
base: main
Are you sure you want to change the base?
Conversation
f18501c
to
e2a36da
Compare
@miguelfrde Changing dependency always require justification why new crate is better and risk is less. I dislike My expectation on error handling: not hiding root cause or origin of error. For example, when a missformed netlink message has invalid MTU data length, I am expecting error message indicate so instead of saying If you want to introduce new crate |
I totally understand the concern of not wanting to depend on new crates. Fwiw this crate is mostly a convenience on top of
I believe with this approach I'm taking, this can be accomplished. A pattern I've grown to like is to leverage In my opinion, I wrote this toy example to demonstrate that we can get the origin of the error and the entire trace of errors if we correctly leverage the In this case we get a nice message showing the top level error plus all of the underlying errors that got us there:
I have a follow-up for this change in rust-netlink/netlink-packet-route#118 I think this approach gets us what we both desire! Let me know your thoughts. I'm more than happy to accommodate this PR to accomplish both human readable messages and machine usable errors. |
This improves matching on particular errors when we need to handle different conditions downstream. It's still possible to convert a anyhow::Error to a DecodeError in this change, but every other error this crate expsoes is now in a variant.
Huge +1 from me on the idea. The reason I went for untyped errors initially is that it allowed me to move fast in the first stages of the project. I've thought of moving to thiserror in the past, but was discouraged by the amount of work. I like I'll try to find some time to review this in more details. Note that if we go with types errors, we should try to make it right from the start, because making changes to an error type will be a breaking change in the future. Thanks for starting this @miguelfrde ! |
@little-dude Anything that we need to do to move this forward? Thanks! |
Hey @gbbosak, I apologize for not moving on this. I have very little time/energy/motivation to dedicate to open-source these days and I've been postponing this for far too long. I have a project to push past the finish line by end of this month at work, but I'll review first week of August. |
This improves matching on particular errors when we need to handle them differently downstream. At the moment we would need to be matching error strings which is brittle and not ideal.
For now I left the possibility of converting a
anyhow::Error
to aDecodeError
in this change, but every other error this crate exposes is now a variant ofDecodeError
. I've leftEncodeError
untouched.I'm preparing a change on top of this one in the netlink-packet-route crate as well that makes that create expose more granular errors that can be matched against.
Bug #10