Skip to content

Introduce a formatter sigil for "alternate" Display #1311

Open
@thomaseizinger

Description

@thomaseizinger

Feature Request

Motivation

anyhow provides a formatting of the whole error chain through the alternate selector {:#}: https://docs.rs/anyhow/1.0.38/anyhow/struct.Error.html#display-representations

It would be nice to make use of this within tracing events in a concise way.

Proposal

Add a formatter sigil (possibly #) to tracing that allows to print values using their alternate Display implementation.

For example:

let error = anyhow!("Oh noes!").context("Something went horribly wrong!");

tracing::error!(#error, "What a mess")

Would print as:

ERROR What a mess error=Something went horribly wrong!: Oh noes!

Alternative

One can convert an anyhow error into a std-error. If reporting std-errors were to be made more ergonomic AND tracing provides a way of printing all causes of std-errors, then this feature is not needed. That being said, triggering the alternative Display impl is not specific to anyhow and might be useful in general.

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