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 => {
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(())
}