feat: add annotate() method to Context

to just annotate the passed error with location data

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2023-07-28 17:06:10 +02:00
parent 101d2074e1
commit 46b7f58e72
Signed by: harald
GPG key ID: 900F3C4971086004
2 changed files with 38 additions and 2 deletions

View file

@ -1,4 +1,4 @@
use chainerror::prelude::v2::*;
use chainerror::Context as _;
use std::error::Error;
use std::fmt;
use std::io;
@ -8,12 +8,17 @@ fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Ok(())
}
fn func3() -> Result<(), Box<dyn Error + Send + Sync>> {
fn func4() -> Result<(), Box<dyn Error + Send + Sync>> {
let filename = "foo.txt";
do_some_io().context(format!("Error reading '{}'", filename))?;
Ok(())
}
fn func3() -> Result<(), Box<dyn Error + Send + Sync>> {
func4().annotate()?;
Ok(())
}
chainerror::str_context!(Func2Error);
fn func2() -> chainerror::Result<(), Func2Error> {