You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An Error likely has a message, it might have a cause, and someday, it may have a trace/frame. How should they be formatted? What is a good default, and how should a user configure to their needs?
Output options:
Top message only
ship exploded
Top message + message of source chain
ship exploded: cat hair in generator
Top message + message of source chain + trace/frame
ship exploded
at main.rs:55
at ship.rs:89
Caused by: cat hair in generator
at ship::parts::generator.rs:33
at ship::parts::engine.rs:789
at ship.rs:89
at main.rs:55
User format flags:
The user can specify some flags when trying to format a value:
Default: {}
Alternative: {:#}
Plus: {:+}
Currently only used by numerics, so Errors could interpret this differently.
Precision: {:.3}
Currently defined for floats and strings. For strings, implies a "maximum width" of a string.
We could hijack this for Errors to mean "maximum iterators down source chain"
Proposed usage
Default ({}): Print only the top-level message. This is inline with the recommendation for Error
Example: println!("top only = {}", err) outputs top only = ship exploded.
Alternative: This could also be achieved and possibly clearer by setting the "precision" flag to 0, such as println!("top only: {:.0}", err).
Message chain ({:+}): Prints the message, and the message of each source, joined by ": ".
An
Error
likely has a message, it might have a cause, and someday, it may have a trace/frame. How should they be formatted? What is a good default, and how should a user configure to their needs?Output options:
Top message only
Top message + message of source chain
Top message + message of source chain + trace/frame
User format flags:
The user can specify some flags when trying to format a value:
{}
{:#}
{:+}
Error
s could interpret this differently.{:.3}
Error
s to mean "maximum iterators down source chain"Proposed usage
{}
): Print only the top-level message. This is inline with the recommendation forError
println!("top only = {}", err)
outputstop only = ship exploded
.println!("top only: {:.0}", err)
.{:+}
): Prints the message, and the message of each source, joined by": "
.println!("chain = {:+}", err)
outputschain = ship exploded: cat hair in generator
.{:#}
): Prints the message and stack trace/frameprintln!("top trace = {:#}", err)
outputstop trace = ship exploded\n at ship.rs:89
.{:+#}
): Prints the message and stack trace/frame, and message and trace for each source, joined by\nCaused by:
.{:+.2}
): Sets the maximum messages that should be printed down the source chain.The text was updated successfully, but these errors were encountered: