Unify error messages, closes #342
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 6ff58ab · Browse files · 4 files·+12 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+12 added−12 removed
- other:+12 added−12 removed
Provenance
- Commit
81a27fa- Tree
3a9c26b- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
6ff58ab
4 files changed+12 added−12 removed
modified:src/exec/command.rs+2 added-2 removed
28 unmodified lines29 let _ = stdout.lock().write_all(&output.stdout);30 let _ = stderr.lock().write_all(&output.stderr);31 }32 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {33- print_error!("fd: execution error: command not found");33+ print_error!("Command not found: {:?}", cmd);34 }35 Err(why) => {36- print_error!("fd: execution error: {}", why);36+ print_error!("Problem while executing command: {}", why);37 }38 }39 }modified:src/internal/mod.rs+1 added-1 removed
15 unmodified lines16 pub mod filter;17 pub mod opts;18 19 macro_rules! print_error {20- ($($arg:tt)*) => (eprintln!($($arg)*))20+ ($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*)))21 }22 23 macro_rules! print_error_and_exit {24 ($($arg:tt)*) => {149 unmodified linesmodified:src/main.rs+6 added-6 removed
56 unmodified lines57 58 // Get the current working directory59 let current_dir = Path::new(".");60 if !fshelper::is_dir(current_dir) {61- print_error_and_exit!("Error: could not get current directory.");61+ print_error_and_exit!("Could not get current directory.");62 }63 64 // Get one or more root directories to search.65 let mut dir_vec: Vec<_> = match matches4 unmodified lines70 .map(|path| {71 let path_buffer = PathBuf::from(path);72 if !fshelper::is_dir(&path_buffer) {73 print_error_and_exit!(74- "Error: '{}' is not a directory.",74+ "'{}' is not a directory.",75 path_buffer.to_string_lossy()76 );77 }78 path_buffer19 unmodified lines98 && pattern.contains(std::path::MAIN_SEPARATOR)99 && fshelper::is_dir(Path::new(pattern))100 {101 print_error_and_exit!(102- "Error: The search pattern '{pattern}' contains a path-separation character ('{sep}') \102+ "The search pattern '{pattern}' contains a path-separation character ('{sep}') \103 and will not lead to any search results.\n\n\104 If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \105 fd . '{pattern}'\n\n\106 Instead, if you want to search for the pattern in the full path, use:\n\n \43 unmodified lines150 v.map(|sf| {151 if let Some(f) = SizeFilter::from_string(sf) {152 return f;153 }154- print_error_and_exit!("Error: {} is not a valid size constraint.", sf);154+ print_error_and_exit!("'{}' is not a valid size constraint. See 'fd --help'.", sf);155 })156 .collect()157 })158 .unwrap_or_else(|| vec![]);3 unmodified lines162 if let Some(t) = matches.value_of("changed-within") {163 if let Some(f) = TimeFilter::after(&now, t) {164 time_constraints.push(f);165 } else {166- print_error_and_exit!("Error: {} is not a valid time.", t);166+ print_error_and_exit!("'{}' is not a valid date or duration. See 'fd --help'.", t);167 }168 }169 if let Some(t) = matches.value_of("changed-before") {170 if let Some(f) = TimeFilter::before(&now, t) {171 time_constraints.push(f);172 } else {173- print_error_and_exit!("Error: {} is not a valid time.", t);173+ print_error_and_exit!("'{}' is not a valid date or duration. See 'fd --help'.", t);174 }175 }176 177 let config = FdOptions {96 unmodified linesmodified:src/walk.rs+3 added-3 removed
60 unmodified lines61 62 for pattern in &config.exclude_patterns {63 let res = override_builder.add(pattern);64 if res.is_err() {65- print_error_and_exit!("Error: malformed exclude pattern '{}'", pattern);65+ print_error_and_exit!("Malformed exclude pattern '{}'", pattern);66 }67 }68 let overrides = override_builder.build().unwrap_or_else(|_| {69 print_error_and_exit!("Mismatch in exclude patterns");23 unmodified lines93 _ => {94 print_error!(95 "{}",96 format!(97- "Error while parsing custom ignore file '{}': {}.",97+ "Malformed pattern in custom ignore file '{}': {}.",98 ignore_file.to_string_lossy(),99 err.description()100 )101 );216 unmodified lines318 let search_str_o = if config.search_full_path {319 match fshelper::path_absolute_form(entry_path) {320 Ok(path_abs_buf) => Some(path_abs_buf.to_string_lossy().into_owned().into()),321 Err(_) => {322- print_error_and_exit!("Error: unable to get full path.");322+ print_error_and_exit!("Unable to retrieve absolute path.");323 }324 }325 } else {326 entry_path.file_name().map(|f| f.to_string_lossy())26 unmodified lines