Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't print an empty "error:" line in the CLI #670

Merged
merged 1 commit into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/bin/tectonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ fn main() {
"this is a BETA release; ask questions and report bugs at https://tectonic.newton.cx/"
);

// Now that we've got colorized output, we're to pass off to the inner
// function ... all so that we can print out the word "error:" in red.
// This code parallels various bits of the `error_chain` crate.
// Now that we've got colorized output, pass off to the inner function ...
// all so that we can print out the word "error:" in red. This code
// parallels various bits of the `error_chain` crate.

if let Err(ref e) = inner(args, config, &mut *status) {
tt_error!(status, ""; e);
status.report_error(e);
process::exit(1)
}
}
17 changes: 17 additions & 0 deletions src/status/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,25 @@ pub enum MessageKind {

pub trait StatusBackend {
/// Report a message to the status backend.
///
/// If `err` is not None, it represents an error that somehow caused the
/// current message to be reported. It should be displayed in some
/// appropriate fashion.
fn report(&mut self, kind: MessageKind, args: Arguments, err: Option<&Error>);

/// Report an error to the status backend.
///
/// Unlike the basic `report` function, in this case there is no additional
/// contextual information provided. The default implementation delegates to
/// `report()` with a generic lead-in message of "an error occurred".
fn report_error(&mut self, err: &Error) {
self.report(
MessageKind::Error,
format_args!("an error occurred"),
Some(err),
)
}

/// Issue a note-level status, idealy highlighting a particular phrase.
///
/// This is a bit of a hack. For [`driver::ProcessingSession::run`], I
Expand Down
14 changes: 14 additions & 0 deletions src/status/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ impl StatusBackend for PlainStatusBackend {
}
}

fn report_error(&mut self, err: &Error) {
let mut prefix = "error";

for item in err.iter() {
eprintln!("{}: {}", prefix, item);
prefix = "caused by";
}

if let Some(backtrace) = err.backtrace() {
eprintln!("debugging: backtrace follows:");
eprintln!("{:?}", backtrace);
}
}

fn note_highlighted(&mut self, before: &str, highlighted: &str, after: &str) {
if self.chatter > ChatterLevel::Minimal {
self.report(
Expand Down
21 changes: 21 additions & 0 deletions src/status/termcolor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ impl StatusBackend for TermcolorStatusBackend {
}
}

fn report_error(&mut self, err: &Error) {
let mut first = true;
let kind = MessageKind::Error;

for item in err.iter() {
if first {
self.generic_message(kind, None, format_args!("{}", item));
first = false;
} else {
self.generic_message(kind, Some("caused by:"), format_args!("{}", item));
}
}

if let Some(backtrace) = err.backtrace() {
self.generic_message(kind, Some("debugging:"), format_args!("backtrace follows:"));
self.with_stream(kind, |s| {
writeln!(s, "{:?}", backtrace).expect("backtrace dump failed");
});
}
}

fn note_highlighted(&mut self, before: &str, highlighted: &str, after: &str) {
if self.chatter > ChatterLevel::Minimal {
write!(self.stdout, "{}", before).expect("write to stdout failed");
Expand Down