Skip to content
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
@vorner

Description

@vorner

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions