Skip to content

Debug-printing a Report uses Debug despite crate docs stating Display is used by default #166

@LunarLambda

Description

@LunarLambda

Per https://docs.rs/rootcause/latest/rootcause/handlers/index.html#1-formatting-function-selection :

The default behavior is to always use Display formatting, regardless of how the report itself is being formatted.

All built-in handlers (Error, Display, Debug, Any) use this default behavior, which means they use their display method even when the report is being debug-formatted with {:?}.

However, testing:

// [dependencies]
// rootcause = "0.12.1"

use rootcause::prelude::*;

fn main() -> Result<(), Report> {
    std::fs::File::open("/nonexistent").attach("test")?;

    Ok(())
}

yields (returning Err from main causes Error: {e:?} to be printed):

 ● Os { code: 2, kind: NotFound, message: "No such file or directory" }
 ├ src/main.rs:2
 ╰ "test"

And indeed, digging through the code, Report's Debug impl passes in FormattingFunction::Debug here, which gets threaded to DefaultReportFormatter::format_reports, which asks for the preferred formatting function for Debug here, and then, presumably ought to return a context using FormattingFunction::Display but doesn't, and thus eventually format_item uses Debug.

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