Use the anyhow
crate for error handling
#82
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 includingPacketryError
,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 forOption
andResult
, which allows easily attaching context information when turning an existingNone
orErr
value into ananyhow::Error
. This neatly replaces some existing patterns and ourOnBug
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
orRUST_LIB_BACKTRACE
are set.