Description
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, likeprintln!("Call stack:\n{}", trace)
.