Expand description
An error handling library for portable unrecoverable errors.
This crate provides,
Failurestruct that represents an unrecoverable error with an error code, message and user-level backtrace- Error code and message are optional
- Constituted with simple types (
u32,String, andVecof those)- Portable across process and language boundaries
- Optional [
serde] support (“serde” feature)
- Doesn’t implement
std::error::Errortrait
OrFailtrait- Backtrace location is appended to
Failureeach time when callingOrFail::or_fail() bool,Option<_>andResult<_, _>implementOrFail
- Backtrace location is appended to
Examples
use orfail::{OrFail, Result};
fn check_non_zero(n: isize) -> Result<()> {
(n != 0).or_fail()?;
Ok(())
}
fn safe_div(x: isize, y: isize) -> Result<isize> {
check_non_zero(y).or_fail()?;
Ok(x / y)
}
// OK
assert_eq!(safe_div(4, 2), Ok(2));
// NG
assert_eq!(safe_div(4, 0).err().map(|e| e.to_string()),
Some(
r#"failed due to "expected `true` but got `false`"
at src/lib.rs:7
at src/lib.rs:12
"#.to_owned()));Macros
Similar to
std::todo!() but returning an Err(Failure) instead of panicking.Similar to
std::unreachable!() but returning an Err(Failure) instead of panicking.Structs
Failure typically represents an unrecoverable error with an error code, message, and backtrace.Traits
This trait allows for converting a value into
Result<_, Failure>.A marker trait representing that
C can be converted into the type implementing this trait.