Skip to content

Formatting of std::backtrace::Backtrace #65280

Description

@seanmonstar

View all comments

I'd like to propose some changes to formatting of the Backtrace type introduced in #53487.

  • Don't include newlines in the default Debug output. I personally find it pretty jarring when looking at the debug output of an error where everything is on the same line except the backtrace, and then any additional properties are printed way down on the last line.

    I'd suggest instead printing a "list" of "maps", such that it'd look like [{ function: "errors::new", file: "./src/new.rs", line: 21 }, ...].

  • Allow passing the "precision" format flag to limit how many frames are printed. The most relevant frames are normally near the top, but deciding exactly how many depends on the app. Then a user could write println!("short trace: {:.5}", trace) to see just 5 frames.

  • Remove stack backtrace:\n prefix entirely. When formatting, I'd think a user would pick their own prefix, like println!("Call stack:\n{}", trace).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-backtraceArea: BacktracesC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.PG-error-handlingProject group: Error handling (https://github.com/rust-lang/project-error-handling)T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions