This repository was archived by the owner on Aug 16, 2021. It is now read-only.
This repository was archived by the owner on Aug 16, 2021. It is now read-only.
Wrapping in Context
as attribute #295
Open
Description
Hello
I'm not sure if I'm using the .context
and with_context
things as expected, but I'm trying to build detailed context „chains“ (and print all the levels when logging). However, sometimes doing that requires to jumping through ugly loops like this:
fn do_something(xy: &str) -> Result<Whatever, Error> {
let inner = || {
first_part()?;
second_part()?;
third_part(xy)?;
};
Ok(inner().with_context(|_| format!("Failed to do something about {}", xy)?))
}
So I wonder, now we have the attribute style procedural macros, if it would be possible to do this kind of thing using a decorator like this:
#[failure(with_context = "Failed to do something about {}", xy)]
fn do_something(xy: &str) -> Result<Whatever, Error> {
first_part()?;
second_part()?;
third_part(xy)?;
}
And possibly make it work on try
blocks too.
Anyway, this is a very much rough and unformed idea.
Metadata
Metadata
Assignees
Labels
No labels