Skip to content

Commit

Permalink
Don't print an empty "error:" line in the CLI
Browse files Browse the repository at this point in the history
This change in behavior was introduced in tectonic-typesetting#636 with the genericization
of the status backend. Add a new `report_error` method to recover the
old behavior.

Closes tectonic-typesetting#665.
  • Loading branch information
pkgw committed Nov 1, 2020
1 parent 045dbb5 commit cefe461
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
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

0 comments on commit cefe461

Please sign in to comment.