Skip to content

Commit

Permalink
Parse Error return an Error instead of a successful empty response
Browse files Browse the repository at this point in the history
  • Loading branch information
t-botz committed Jun 9, 2018
1 parent 34067a1 commit 8c32a9d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib.rs
Expand Up @@ -132,6 +132,9 @@ pub enum ErrorKind {
/// An io error during reading or writing.
#[fail(display = "io error: {}", _0)]
IoError(io::Error),
/// Parse error occured when parsing the Input.
#[fail(display = "parse error")]
ParseError,
/// The user mandated a version and the current version of Rustfmt does not
/// satisfy that requirement.
#[fail(display = "Version mismatch")]
Expand Down Expand Up @@ -172,9 +175,10 @@ impl FormattingError {
}
fn msg_prefix(&self) -> &str {
match self.kind {
ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace | ErrorKind::IoError(_) => {
"internal error:"
}
ErrorKind::LineOverflow(..)
| ErrorKind::TrailingWhitespace
| ErrorKind::IoError(_)
| ErrorKind::ParseError => "internal error:",
ErrorKind::LicenseCheck | ErrorKind::BadAttr | ErrorKind::VersionMismatch => "error:",
ErrorKind::BadIssue(_) | ErrorKind::DeprecatedAttr => "warning:",
}
Expand Down Expand Up @@ -844,7 +848,7 @@ fn format_input_inner<T: Write>(
ParseError::Recovered => {}
}
summary.add_parsing_error();
return Ok((summary, FileMap::new(), FormatReport::new()));
return Err((ErrorKind::ParseError, summary));
}
};

Expand Down

0 comments on commit 8c32a9d

Please sign in to comment.