use oofs::{oofs, Oof, OofExt};
struct RetryTag;
#[oofs]
fn application() -> Result<(), Oof> {
if let Err(e) = middlelayer("hello world") {
if e.tagged_nested::<RetryTag>() {
println!("Retrying middlelayer!\n");
middlelayer("hello world")?;
} else {
return Err(e);
}
}
Ok(())
}
#[oofs]
fn middlelayer(text: &str) -> Result<u64, Oof> {
let my_struct = MyStruct {
field: text.to_owned(),
};
let ret = my_struct.failing_method(get_value()?)?;
Ok(ret)
}
fn get_value() -> Result<usize, std::io::Error> {
Ok(123)
}
#[derive(Debug)]
struct MyStruct {
field: String,
}
#[oofs]
impl MyStruct {
fn new() -> Result<Self, Oof> {
let field = "hi".to_owned();
Ok(MyStruct {
field
})
}
fn failing_method(&self, x: usize) -> Result<u64, Oof> {
let ret = self
.field
.parse::<u64>()
._tag::<RetryTag>() ._attach(x) ._attach(&self.field) ._attach_lazy(|| "extra context")?;
Ok(ret)
}
}
#[test]
fn implements_basic_error() {
let res = application();
assert!(res.is_err());
let err = res.unwrap_err();
println!("{:?}", err);
}