Macro tectonic_errors::atry
source · macro_rules! atry { (@aa $ar:ident [ $($inner:tt)+ ] ) => { ... }; (@aa $ar:ident ( note $($inner:tt)+ ) ) => { ... }; ($op:expr ; $( $annotation:tt )+) => { ... }; }
Expand description
“Annotated try” — like try!
, but with the ability to add extended context
to the error message. This tries to provide a bit more syntactic sugar than
anyhow’s with_context()
, and it supports our AnnotatedMessage context type.
Example
let ok_val = atry!(
my_fallible_operation(arg, option);
["the operation on `{}` failed", arg]
(note "option was `{}`; maybe you should choose a better value next time", option)
);
This is equivalent to let ok_val = my_fallible_operation(arg)?;
, but if the
operation fails, the returned error will have a message formatted as per the
format expression in square brackets, with attached “note” text formatted as
per the parenthesized note
expression. There may be zero, one, or many notes
attached.