Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically convert to external errors w/ ensure! and bail! (#95)
* Automatically convert to external errors A pattern documented by thiserror is ``` pub enum MyError { ... #[error(transparent)] Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error } ``` It'd be nice for this to work with ensure! but right now, that macro returns an eyre error. With this PR, the macro additionally runs an .into(). In the case that the return type is an eyre error, obviously .into() will do nothing and be compiled away. In the case that there is a from method, the wrapping will occur. This enables eyre to be used for ergonomic 'implementation detail error' in a thiserror using system which has contractual errors. Since this conversion adds more flexibility to the result of these macros, this could break code which relies on the narrowness to inform type inference. If this is the case, update your code to specify the result type you would like to use. * Fix single-argument ensure test and allow dead code. By adding the possibility for polymorphism from an eyre error, the previous commit breaks a previous eyre test for single-argument ensure!(). This change fixes that test and adds `allow(dead_code)` to the struct used for the test for automatically converting to external errors. --------- Co-authored-by: nori li <[email protected]>
- Loading branch information