Module balena_temen::error
source · Expand description
Error handling
A module allowing us to create more detailed, context aware, errors.
Examples
Result chaining example.
use balena_temen::error::*;
fn eval_as_number() -> Result<()> {
Err(Error::with_message("unable to evaluate as a number")
.context("value", "some value")
.context("expected", "number"))
}
fn eval_math() -> Result<()> {
Ok(eval_as_number()
.frame_with(|| "eval_math".into())
.context_with(|| ("rhs".to_string(), "`23`".to_string()))?)
}
fn eval() -> Result<()> {
Ok(eval_math().frame_with_name("eval").context("expression", "1 = `23`")?)
}
eprintln!("{}", eval().err().unwrap());
Printed error:
temen: unable to evaluate as a number
├ frame[0]
| └ context:
| ├ value: some value
| └ expected: number
├ frame[1]: eval_math
| └ context:
| └ rhs: `23`
└ frame[2]: eval
└ context:
└ expression: 1 = `23`
Structs
Error type
Traits
Result extension
Type Definitions
Standard library result wrapper