error-chain 0.7.1 is out. This release reverts some changes from the 0.6 series that caused regressions in inference and usability. It also comes with a new bail!
macro, syntax sugar for early return with type conversions.
The main things to be aware of compared to 0.6:
Declaring links { }
again requires the ErrorKind
name:
links {
Utils(::utils::Error, ::utils::ErrorKind);
}
The ResultExt
trait is once again defined by the error_chain!
macro, not in the error_chain
crate, and so must be mentioned in the types { }
block:
types {
Error, ErrorKind, ResultExt, Result;
}
The Error
kind is again a tuple, not a struct, and is matched like a tuple:
match Error::from("error!") {
Error(ErrorKind::InvalidToolchainName(_), _) => { }
Error(ErrorKind::Msg(_), _) => { }
}
And the bail!
macro:
fn foo() -> Result<()> {
if bad_condition() {
bail!(ErrorKind::FooError);
}
Ok(())
}
Which also works with fmt specifiers:
fn foo() -> Result<()> {
if bad_condition() {
bail!("bad stuff happened: {}", bad_stuff);
}
Ok(())
}
The bail!
macro is inspired by a similar macro in Cargo and a similar throw
construct in the exception handling RFC.
Finally, thanks to @Yamakaky for taking on some of the error-chain maintenance responsibilities in the last few weeks.
Contributors: Brian Anderson, Yamakaky
0.7.1
0.7.0
- Rollback several design changes to fix regressions
- New
Variant(Error) #[attrs]
forlinks
andforeign_links
. - Hide implementation details from the doc.
- Always generate
Error::backtrace
.