-
Notifications
You must be signed in to change notification settings - Fork 53
[RFC] Switched error handling to anyhow #81
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
Conversation
@rdelfin - thanks for the PR. I haven't used So far it looks like all the CI tests are failing. @jvns - do you have any experience with |
let cname = | ||
CString::new(name).map_err(|_| format_err!("Nul byte in Kprobe name: {}", name))?; | ||
CString::new(name).map_err(|_| anyhow::anyhow!("Nul byte in Kprobe name: {}", name))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like anyhow exports format_err!
? If so, that could save a lot of lines in this diff by doing use anyhow::*;
Cargo.toml
Outdated
@@ -12,6 +12,7 @@ homepage = "https://github.com/rust-bpf/rust-bcc" | |||
edition = '2018' | |||
|
|||
[dependencies] | |||
anyhow = "1.0.26" | |||
bcc-sys = "0.12.0" | |||
byteorder = "1.3.1" | |||
failure = "0.1.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we'd want to remove failure
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Let me switch it up then
Glad to help out. I've mostly figured out the CI failures (seems to be I just missed fixing the examples). I'll send out a fix. The point on backtraces is... Interesting. anyhow does support returning backtraces. However, where failure has it's own backtrace type, anyhow return an std::backtrace::Backtrace, which seems to still be on the rust nightly builds only. If you feel like this is a vital component of the library, it could make sense to hold off this PR until the feature becomes stable. |
cc @kamalmarhubi who knows more about the current state of rust error handling than me |
I haven't been keeping up super closely with the RFC to fix the error trait which came out of issues with failure which are discussed at some length in rust-lang-deprecated/failure#209. That said, my understanding of the best practices for a library is to just define a custom error type that implements Alternatively, you could replace In any case, I'd be wary of changing from failure to a different library without a bit more understanding of where RFC 2504 & backtrace support in std is at. Changing to a custom type or |
That all makes a lot of sense. @kamalmarhubi would it make more sense then to change the library to use something like |
Closing this one out since #88 is now merged |
As of rust 1.34+, many crates have switched to using anyhow for error handling. This is because anyhow provides support for returning any error implementing
std::error::Error
. This change basically replaces out all uses of thefailure
crate withanyhow
. This could cause two potential issues:Overall though, I believe this change could be worth it for the upside of allowing clients to use any error type that implements
std::error::Error
.