Skip to content

Commit

Permalink
Make Report::report print the "Error: " prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
DerickEddington authored and shepmaster committed May 24, 2024
1 parent 36c6bbe commit 53c4f63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ where
match self.0 {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("{}", ReportFormatter(&e));
eprintln!("Error: {}", ReportFormatter(&e));

#[cfg(feature = "unstable-provider-api")]
{
Expand Down
16 changes: 16 additions & 0 deletions tests/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ fn debug_and_display_are_the_same() {
assert_eq!(display, debug);
}

/// `Report as Termination` prints-out the "Error:" prefix. Ensure that `Report as Display` does
/// not also add such a prefix, to avoid printing-out "Error: Error: ...".
#[test]
fn display_not_prefixed() {
#[derive(Debug, Snafu)]
#[snafu(display("This is my Display text!"))]
struct Error;

let r = Report::from_error(Error);
let msg = r.to_string();
let msg = msg.trim_start();

assert!(!msg.starts_with("Err"));
assert!(!msg.starts_with("err"));
}

#[test]
fn procedural_macro_works_with_result_return_type() {
#[derive(Debug, Snafu)]
Expand Down

0 comments on commit 53c4f63

Please sign in to comment.