Skip to content
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 the anyhow crate for error handling #82

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

martinling
Copy link
Member

Use the anyhow crate for error handling.

This crate provides:

  • The anyhow::Error type, which wraps any other error type, and can thus replace the whole error type hierarchy we have currently including PacketryError, CaptureError, StreamError, ModelError etc.

  • A bail! macro which can simplify sites where we just want to return an error with some text.

  • A Context trait, implemented for Option and Result, which allows easily attaching context information when turning an existing None or Err value into an anyhow::Error. This neatly replaces some existing patterns and our OnBug trait.

As well as simplifying the code, this change enables us to display a backtrace for any error - this is implemented in the second commit. Backtraces are only captured if RUST_BACKTRACE or RUST_LIB_BACKTRACE are set.

@miek
Copy link
Member

miek commented Jan 8, 2024

I've pushed some CI fixes, could you rebase?

@martinling martinling force-pushed the anyhow branch 2 times, most recently from 039445b to 2f67832 Compare January 8, 2024 15:37
@martinling
Copy link
Member Author

Passing CI now.

@miek miek merged commit 72d2041 into greatscottgadgets:main Jan 8, 2024
6 checks passed
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.

2 participants