[][src]Crate fn_error_context

This crate provides the context macro for adding extra error information to a function.

Works with anyhow, failure and any other error type which provides a context method taking a string.

use fn_error_context::context;

#[context("failed to parse config at `{}`", path.as_ref().display())]
pub fn parse_config(path: impl AsRef<Path>) -> anyhow::Result<u32> {
    let text = read_to_string(path.as_ref())?;
    Ok(text.parse()?)
}

assert_eq!(
    parse_config("not-found").unwrap_err().to_string(),
    "failed to parse config at `not-found`"
);

Attribute Macros

context

Add context to errors from a function.