Skip to content

Ergonomic Reporting of std::error::Error #1308

Open
@theduke

Description

@theduke

Feature Request

Find some more ergonomic way to report std::error::Error values.

Crates

  • tracing

Motivation

Logging a type that implements std::error::Error is currently quite awkward.
Value is only implemented for dyn std::error::Error.

That means logging a concrete type involves awkward type gymanstics for something that is a very common operation.

(unless I'm missing some trick here...)

EG:

// Inline
info!(error = &err as &dyn std::error::Error, "msg");

// Helper variable
let error: &dyn std::error::Error = &err;
info!(error, "msg");

Proposal

Not sure what would be the best way to implement this.
A generic default impl is probably out of the question without specialization.

The most straight-forward solution would probably be a new formatter sigil, eg !.

warn!( error = !err, "msg");

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