From c6f75b9079896f2ce326a7d85c687f3df0b8c858 Mon Sep 17 00:00:00 2001 From: BryanFRD Date: Mon, 5 Oct 2026 20:32:00 +0200 Subject: [PATCH] fix(cli): indent a multi-line error head below the causes --- src/error_report.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/error_report.rs b/src/error_report.rs index 7c7bcd76..d2b91959 100644 --- a/src/error_report.rs +++ b/src/error_report.rs @@ -25,7 +25,7 @@ pub fn error_report_lines(err: &anyhow::Error) -> Vec { .first() .map(String::as_str) .unwrap_or("unknown error"); - push_message(&mut lines, &format!("error[{code}]: "), " ", head); + push_message(&mut lines, &format!("error[{code}]: "), " ", head); for cause in causes.iter().skip(1) { push_message(&mut lines, " ", " ", cause); } @@ -125,8 +125,26 @@ mod tests { lines[..3], [ "error[E6102]: cargo publish failed for core on forgejo: error: failed to prepare local package", - " Caused by:", - " no matching package named `core` found", + " Caused by:", + " no matching package named `core` found", + ] + ); + } + + #[test] + fn a_multi_line_coded_head_stays_apart_from_the_next_cause() { + let err = anyhow::Result::<()>::Err(anyhow::anyhow!("permission denied")) + .context("could not publish\nregistry said no") + .error_code(error_code::PUBLISH_FAILED) + .unwrap_err(); + + let lines = error_report_lines(&err); + assert_eq!( + lines[..3], + [ + "error[E6102]: could not publish", + " registry said no", + " permission denied", ] ); }