Unify error messages, closes #342

This commit is contained in:
sharkdp 2018-10-27 16:30:29 +02:00
parent 6ff58abb6c
commit 81a27fa9bd
4 changed files with 12 additions and 12 deletions

View File

@ -30,10 +30,10 @@ pub fn execute_command(mut cmd: Command, out_perm: Arc<Mutex<()>>) {
let _ = stderr.lock().write_all(&output.stderr);
}
Err(ref why) if why.kind() == io::ErrorKind::NotFound => {
print_error!("fd: execution error: command not found");
print_error!("Command not found: {:?}", cmd);
}
Err(why) => {
print_error!("fd: execution error: {}", why);
print_error!("Problem while executing command: {}", why);
}
}
}

View File

@ -17,7 +17,7 @@ pub mod filter;
pub mod opts;
macro_rules! print_error {
($($arg:tt)*) => (eprintln!($($arg)*))
($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*)))
}
macro_rules! print_error_and_exit {

View File

@ -58,7 +58,7 @@ fn main() {
// Get the current working directory
let current_dir = Path::new(".");
if !fshelper::is_dir(current_dir) {
print_error_and_exit!("Error: could not get current directory.");
print_error_and_exit!("Could not get current directory.");
}
// Get one or more root directories to search.
@ -71,7 +71,7 @@ fn main() {
let path_buffer = PathBuf::from(path);
if !fshelper::is_dir(&path_buffer) {
print_error_and_exit!(
"Error: '{}' is not a directory.",
"'{}' is not a directory.",
path_buffer.to_string_lossy()
);
}
@ -99,7 +99,7 @@ fn main() {
&& fshelper::is_dir(Path::new(pattern))
{
print_error_and_exit!(
"Error: The search pattern '{pattern}' contains a path-separation character ('{sep}') \
"The search pattern '{pattern}' contains a path-separation character ('{sep}') \
and will not lead to any search results.\n\n\
If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \
fd . '{pattern}'\n\n\
@ -151,7 +151,7 @@ fn main() {
if let Some(f) = SizeFilter::from_string(sf) {
return f;
}
print_error_and_exit!("Error: {} is not a valid size constraint.", sf);
print_error_and_exit!("'{}' is not a valid size constraint. See 'fd --help'.", sf);
})
.collect()
})
@ -163,14 +163,14 @@ fn main() {
if let Some(f) = TimeFilter::after(&now, t) {
time_constraints.push(f);
} else {
print_error_and_exit!("Error: {} is not a valid time.", t);
print_error_and_exit!("'{}' is not a valid date or duration. See 'fd --help'.", t);
}
}
if let Some(t) = matches.value_of("changed-before") {
if let Some(f) = TimeFilter::before(&now, t) {
time_constraints.push(f);
} else {
print_error_and_exit!("Error: {} is not a valid time.", t);
print_error_and_exit!("'{}' is not a valid date or duration. See 'fd --help'.", t);
}
}

View File

@ -62,7 +62,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
for pattern in &config.exclude_patterns {
let res = override_builder.add(pattern);
if res.is_err() {
print_error_and_exit!("Error: malformed exclude pattern '{}'", pattern);
print_error_and_exit!("Malformed exclude pattern '{}'", pattern);
}
}
let overrides = override_builder.build().unwrap_or_else(|_| {
@ -94,7 +94,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
print_error!(
"{}",
format!(
"Error while parsing custom ignore file '{}': {}.",
"Malformed pattern in custom ignore file '{}': {}.",
ignore_file.to_string_lossy(),
err.description()
)
@ -319,7 +319,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
match fshelper::path_absolute_form(entry_path) {
Ok(path_abs_buf) => Some(path_abs_buf.to_string_lossy().into_owned().into()),
Err(_) => {
print_error_and_exit!("Error: unable to get full path.");
print_error_and_exit!("Unable to retrieve absolute path.");
}
}
} else {