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.
This commit is contained in:
Martin von Zweigbergk 2024-03-31 08:51:33 -07:00 committed by Martin von Zweigbergk
parent aeaab8aad3
commit b940f1a092

View file

@ -561,7 +561,7 @@ fn try_handle_command_result(
CommandErrorKind::Config => { CommandErrorKind::Config => {
print_error(ui, "Config error: ", err, hints)?; print_error(ui, "Config error: ", err, hints)?;
writeln!( writeln!(
ui.hint_no_heading(), ui.stderr_formatter().labeled("hint"),
"For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md." "For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md."
)?; )?;
Ok(ExitCode::from(1)) 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<()> { fn print_error_hints(ui: &Ui, hints: &[ErrorHint]) -> io::Result<()> {
for hint in hints { for hint in hints {
match hint { ui.stderr_formatter().with_label("hint", |formatter| {
ErrorHint::PlainText(message) => { write!(formatter.labeled("heading"), "Hint: ")?;
writeln!(ui.hint_default(), "{message}")?; match hint {
} ErrorHint::PlainText(message) => {
ErrorHint::Formatted(recorded) => { writeln!(formatter, "{message}")?;
ui.stderr_formatter().with_label("hint", |formatter| { Ok(())
write!(formatter.labeled("heading"), "Hint: ")?; }
ErrorHint::Formatted(recorded) => {
recorded.replay(formatter)?; recorded.replay(formatter)?;
// Formatted hint is usually multi-line text, and it's // Formatted hint is usually multi-line text, and it's
// convenient if trailing "\n" doesn't have to be omitted. // 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)?; writeln!(formatter)?;
} }
Ok(()) Ok(())
})?; }
} }
} })?;
} }
Ok(()) Ok(())
} }