Closed DerickEddington closed 3 months ago
The problem arises from the fact that we support older versions of Rust:
[dependencies]
snafu = { version = "0.8.2", default-features = false }
use snafu::prelude::*;
#[snafu::report]
fn main() -> Result<(), Error> {
Err(Error)
}
#[derive(Debug, Snafu)]
struct Error;
% cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/whawha`
Error: Error
When targeting older versions of Rust, we transform main
into
fn main() -> Result<(), Report<Error>>
When targeting newer versions:
fn main() -> Report<Error>
As you said, the standard library is the one that adds the Error:
prefix when printing out the Result
.
Your fix seems like the right direction, we just need to ensure that we don't end up printing Error: Error: ...
when older versions of Rust are targeted.
In
src/report.md
, it says the example's printed output will be prefixed with "Error: " [1]:But when the example, or any other program using
Report
as the return type of themain
function, is actually run, its output is not prefixed like that, and its actual output is like:I'm guessing the original intention was for this to print the "Error: " prefix, because
src/report.md
saying that it will is part of the same commit where the actual formatting was introduced [2].I'd prefer if this did print the prefix, because I rely on that to more easily notice when there was an error (vs. non-error printed output), and because that would be more consistent with the
std
library's printing [3] and with other error-helping libraries IIRC.Maybe fixing this is as simple as: