Skip to content

modernize error handling #88

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

Merged
merged 4 commits into from
Jun 29, 2020
Merged

Conversation

brayniac
Copy link
Collaborator

@brayniac brayniac commented Jun 12, 2020

Problem

Currently, we do error handling with the failure crate which
requires that users are aware of failure and use it in their
library or application.

Solution

Switch error handling to use the thiserror crate which allows us
to derive std::error::Error for our error type.

Result

This library's public API now uses std::error::Error in the
Results. This allows better composition within higher level
libraries and applications.

This will be a breaking change to the existing API.

Notes to reviewers

Some of the Error variants might need better naming / error messages, we should try to get naming correct on this pass to avoid additional breaking changes.

Particular areas to focus on:

  • should we make order of words within the variant consistent? "AttachKprobe" vs "TableDelete" has the verb and noun in opposite orders, but seems natural?
  • if we go with natural sounding variants, do the ones listed make sense?
  • tense "Attach" vs "Loading"
  • do we capture enough context for each error?

This PR would replace #81 - my understanding is that anyhow would be appropriate for an application, but we should use thiserror within libraries.

Came across this post, which inspired me to convert to thiserror:
https://nick.groenen.me/posts/rust-error-handling/

@brayniac brayniac requested a review from jvns June 12, 2020 23:14
@brayniac
Copy link
Collaborator Author

@rdelfin you might be interested in taking a look at this.

@rdelfin
Copy link
Contributor

rdelfin commented Jun 16, 2020

Oooh this is nice! I'll be looking forwards to the merge. Using thiserror makes a lot of sense

@brayniac brayniac force-pushed the error-handling branch 2 times, most recently from 2dfe265 to 35bf144 Compare June 18, 2020 18:27
Problem

Currently, we do error handling with the `failure` crate which
requires that users are aware of `failure` and use it in their
library or application.

Solution

Switch error handling to use the `thiserror` crate which allows us
to derive `std::error::Error` for our error type.

Result

This library's public API now uses `std::error::Error` in the
`Result`s. This allows better composition within higher level
libraries and applications.
Copy link

@kamalmarhubi kamalmarhubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That blog post is great! Using thiserror my makes a lot of sense. It not showing up in the API is great. Thanks for linking it.

I can't really makes useful comments on the actual errors as I've never done any bpf things. As for naming, being consistent would be great but I don't know which style you should go with.

@jvns
Copy link
Collaborator

jvns commented Jun 24, 2020

sorry for the slow reply -- I haven't written any Rust for like a year and so I'm unlikely to be that helpful :). this seems reasonable to me!

@brayniac
Copy link
Collaborator Author

Fixing some of the error names for consistency, I will merge following successful CI run.

@brayniac brayniac merged commit 1b0e6ac into rust-bpf:master Jun 29, 2020
@brayniac brayniac deleted the error-handling branch June 29, 2020 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants