Merge pull request #2274 from topecongiro/better-error-msg

Attempt to improve error meassage from rustfmt
This commit is contained in:
Nick Cameron 2017-12-12 16:55:55 +13:00 committed by GitHub
commit 30abfd65a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 26 deletions

View file

@ -350,7 +350,7 @@ fn main() {
}
}
Err(e) => {
print_usage_to_stderr(&opts, &e.to_string());
eprintln!("{}", e.to_string());
1
}
};
@ -364,23 +364,18 @@ fn main() {
std::process::exit(exit_code);
}
macro_rules! print_usage {
($print:ident, $opts:ident, $reason:expr) => ({
let msg = format!(
"{}\n\nusage: {} [options] <file>...",
$reason,
env::args_os().next().unwrap().to_string_lossy()
);
$print!("{}", $opts.usage(&msg));
})
}
fn print_usage_to_stdout(opts: &Options, reason: &str) {
print_usage!(println, opts, reason);
}
fn print_usage_to_stderr(opts: &Options, reason: &str) {
print_usage!(eprintln, opts, reason);
let sep = if reason.is_empty() {
String::new()
} else {
format!("{}\n\n", reason)
};
let msg = format!(
"{}Format Rust code\n\nusage: {} [options] <file>...",
sep,
env::args_os().next().unwrap().to_string_lossy()
);
println!("{}", opts.usage(&msg));
}
fn print_version() {

View file

@ -394,22 +394,23 @@ macro_rules! create_config {
$(
stringify!($i) => (),
)+
_ => {
let msg =
&format!("Warning: Unknown configuration option `{}`\n",
key);
err.push_str(msg)
}
_ => {
let msg =
&format!("Warning: Unknown configuration option `{}`\n", key);
err.push_str(msg)
}
}
}
}
match parsed.try_into() {
Ok(parsed_config) =>
Ok(Config::default().fill_from_parsed_config(parsed_config)),
Ok(parsed_config) => {
eprintln!("{}", err);
Ok(Config::default().fill_from_parsed_config(parsed_config))
}
Err(e) => {
err.push_str("Error: Decoding config file failed:\n");
err.push_str(format!("{}\n", e).as_str());
err.push_str("Please check your config file.\n");
err.push_str("Please check your config file.");
Err(err)
}
}