From b940f1a09223d5a9dfc3c347d5625918be4dd0a3 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 31 Mar 2024 08:51:33 -0700 Subject: [PATCH] errors: don't use the `ui.hint*()` helpers I'm about to make hints not get printed with `--quiet`, but error hints are probably still useful to get. They shouldn't be a problem for scripts since the script would have to deal with the error anyway. --- cli/src/command_error.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/src/command_error.rs b/cli/src/command_error.rs index d0aa801ab..4aa87af6a 100644 --- a/cli/src/command_error.rs +++ b/cli/src/command_error.rs @@ -561,7 +561,7 @@ fn try_handle_command_result( CommandErrorKind::Config => { print_error(ui, "Config error: ", err, hints)?; writeln!( - ui.hint_no_heading(), + ui.stderr_formatter().labeled("hint"), "For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md." )?; Ok(ExitCode::from(1)) @@ -619,13 +619,14 @@ fn print_error_sources(ui: &Ui, source: Option<&dyn error::Error>) -> io::Result fn print_error_hints(ui: &Ui, hints: &[ErrorHint]) -> io::Result<()> { for hint in hints { - match hint { - ErrorHint::PlainText(message) => { - writeln!(ui.hint_default(), "{message}")?; - } - ErrorHint::Formatted(recorded) => { - ui.stderr_formatter().with_label("hint", |formatter| { - write!(formatter.labeled("heading"), "Hint: ")?; + ui.stderr_formatter().with_label("hint", |formatter| { + write!(formatter.labeled("heading"), "Hint: ")?; + match hint { + ErrorHint::PlainText(message) => { + writeln!(formatter, "{message}")?; + Ok(()) + } + ErrorHint::Formatted(recorded) => { recorded.replay(formatter)?; // Formatted hint is usually multi-line text, and it's // convenient if trailing "\n" doesn't have to be omitted. @@ -633,9 +634,9 @@ fn print_error_hints(ui: &Ui, hints: &[ErrorHint]) -> io::Result<()> { writeln!(formatter)?; } Ok(()) - })?; + } } - } + })?; } Ok(()) }