From 3bce55f569f98e4e7816880de035cfa837123c74 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 26 Mar 2017 17:35:50 +0100 Subject: [PATCH] Run Untry over the entire source tree --- src/exa.rs | 20 ++++++++++---------- src/fs/dir.rs | 2 +- src/fs/feature/git.rs | 4 ++-- src/options/dir_action.rs | 4 ++-- src/options/filter.rs | 6 +++--- src/options/mod.rs | 8 ++++---- src/options/view.rs | 16 ++++++++-------- src/output/details.rs | 2 +- src/output/grid.rs | 2 +- src/output/lines.rs | 2 +- 10 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/exa.rs b/src/exa.rs index 50515ec2..8f0147b1 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -72,13 +72,13 @@ impl<'w, W: Write + 'w> Exa<'w, W> { for file_name in self.args.iter() { match File::from_path(Path::new(&file_name), None) { Err(e) => { - try!(writeln!(stderr(), "{}: {}", file_name, e)); + writeln!(stderr(), "{}: {}", file_name, e)?; }, Ok(f) => { if f.is_directory() && !self.options.dir_action.treat_dirs_as_files() { match f.to_dir(self.options.should_scan_for_git()) { Ok(d) => dirs.push(d), - Err(e) => try!(writeln!(stderr(), "{}: {}", file_name, e)), + Err(e) => writeln!(stderr(), "{}: {}", file_name, e)?, } } else { @@ -96,7 +96,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> { let is_only_dir = dirs.len() == 1 && no_files; self.options.filter.filter_argument_files(&mut files); - try!(self.print_files(None, files)); + self.print_files(None, files)?; self.print_dirs(dirs, no_files, is_only_dir) } @@ -110,18 +110,18 @@ impl<'w, W: Write + 'w> Exa<'w, W> { first = false; } else { - try!(write!(self.writer, "\n")); + write!(self.writer, "\n")?; } if !is_only_dir { - try!(writeln!(self.writer, "{}:", dir.path.display())); + writeln!(self.writer, "{}:", dir.path.display())?; } let mut children = Vec::new(); for file in dir.files() { match file { Ok(file) => children.push(file), - Err((path, e)) => try!(writeln!(stderr(), "[{}: {}]", path.display(), e)), + Err((path, e)) => writeln!(stderr(), "[{}: {}]", path.display(), e)?, } }; @@ -136,17 +136,17 @@ impl<'w, W: Write + 'w> Exa<'w, W> { for child_dir in children.iter().filter(|f| f.is_directory()) { match child_dir.to_dir(false) { Ok(d) => child_dirs.push(d), - Err(e) => try!(writeln!(stderr(), "{}: {}", child_dir.path.display(), e)), + Err(e) => writeln!(stderr(), "{}: {}", child_dir.path.display(), e)?, } } - try!(self.print_files(Some(&dir), children)); - try!(self.print_dirs(child_dirs, false, false)); + self.print_files(Some(&dir), children)?; + self.print_dirs(child_dirs, false, false)?; continue; } } - try!(self.print_files(Some(&dir), children)); + self.print_files(Some(&dir), children)?; } Ok(()) diff --git a/src/fs/dir.rs b/src/fs/dir.rs index 5d3fb26b..32347365 100644 --- a/src/fs/dir.rs +++ b/src/fs/dir.rs @@ -33,7 +33,7 @@ impl Dir { /// isn't actually a directory, or if there's an IO error that occurs /// while scanning. pub fn read_dir(path: &Path, git: bool) -> IOResult { - let reader = try!(fs::read_dir(path)); + let reader = fs::read_dir(path)?; let contents = try!(reader.map(|e| e.map(|e| e.path())).collect()); Ok(Dir { diff --git a/src/fs/feature/git.rs b/src/fs/feature/git.rs index 121e3020..14080eeb 100644 --- a/src/fs/feature/git.rs +++ b/src/fs/feature/git.rs @@ -15,13 +15,13 @@ impl Git { /// Discover a Git repository on or above this directory, scanning it for /// the files' statuses if one is found. pub fn scan(path: &Path) -> Result { - let repo = try!(git2::Repository::discover(path)); + let repo = git2::Repository::discover(path)?; let workdir = match repo.workdir() { Some(w) => w, None => return Ok(Git { statuses: vec![] }), // bare repo }; - let statuses = try!(repo.statuses(None)).iter() + let statuses = repo.statuses(None)?.iter() .map(|e| (workdir.join(Path::new(e.path().unwrap())), e.status())) .collect(); diff --git a/src/options/dir_action.rs b/src/options/dir_action.rs index 1f3c06b6..d6fa9933 100644 --- a/src/options/dir_action.rs +++ b/src/options/dir_action.rs @@ -36,8 +36,8 @@ impl DirAction { (true, true, _ ) => Err(Misfire::Conflict("recurse", "list-dirs")), (_, true, true ) => Err(Misfire::Conflict("tree", "list-dirs")), - (_ , _, true ) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, true)))), - (true, false, false) => Ok(DirAction::Recurse(try!(RecurseOptions::deduce(matches, false)))), + (_ , _, true ) => Ok(DirAction::Recurse(RecurseOptions::deduce(matches, true)?)), + (true, false, false) => Ok(DirAction::Recurse(RecurseOptions::deduce(matches, false)?)), (false, true, _ ) => Ok(DirAction::AsFile), (false, false, _ ) => Ok(DirAction::List), } diff --git a/src/options/filter.rs b/src/options/filter.rs index ce7d4ba7..b28f56d1 100644 --- a/src/options/filter.rs +++ b/src/options/filter.rs @@ -75,9 +75,9 @@ impl FileFilter { Ok(FileFilter { list_dirs_first: matches.opt_present("group-directories-first"), reverse: matches.opt_present("reverse"), - sort_field: try!(SortField::deduce(matches)), + sort_field: SortField::deduce(matches)?, show_invisibles: matches.opt_present("all"), - ignore_patterns: try!(IgnorePatterns::deduce(matches)), + ignore_patterns: IgnorePatterns::deduce(matches)?, }) } @@ -265,7 +265,7 @@ impl IgnorePatterns { }; Ok(IgnorePatterns { - patterns: try!(patterns), + patterns: patterns?, }) } diff --git a/src/options/mod.rs b/src/options/mod.rs index f5c8c749..b6665030 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -120,7 +120,7 @@ impl Options { return Err(Misfire::Version); } - let options = try!(Options::deduce(&matches)); + let options = Options::deduce(&matches)?; Ok((options, matches.free)) } @@ -138,9 +138,9 @@ impl Options { /// Determines the complete set of options based on the given command-line /// arguments, after they’ve been parsed. fn deduce(matches: &getopts::Matches) -> Result { - let dir_action = try!(DirAction::deduce(&matches)); - let filter = try!(FileFilter::deduce(&matches)); - let view = try!(View::deduce(&matches, filter.clone(), dir_action)); + let dir_action = DirAction::deduce(&matches)?; + let filter = FileFilter::deduce(&matches)?; + let view = View::deduce(&matches, filter.clone(), dir_action)?; Ok(Options { dir_action: dir_action, diff --git a/src/options/view.rs b/src/options/view.rs index 69cbca4d..06f76ba5 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -37,7 +37,7 @@ impl View { Err(Useless("oneline", true, "long")) } else { - let term_colours = try!(TerminalColours::deduce(matches)); + let term_colours = TerminalColours::deduce(matches)?; let colours = match term_colours { TerminalColours::Always => Colours::colourful(colour_scale()), TerminalColours::Never => Colours::plain(), @@ -52,7 +52,7 @@ impl View { }; let details = Details { - columns: Some(try!(Columns::deduce(matches))), + columns: Some(Columns::deduce(matches)?), header: matches.opt_present("header"), recurse: dir_action.recurse_options(), filter: filter.clone(), @@ -86,8 +86,8 @@ impl View { }; let other_options_scan = || { - let term_colours = try!(TerminalColours::deduce(matches)); - let term_width = try!(TerminalWidth::deduce()); + let term_colours = TerminalColours::deduce(matches)?; + let term_width = TerminalWidth::deduce()?; if let Some(&width) = term_width.as_ref() { let colours = match term_colours { @@ -164,7 +164,7 @@ impl View { }; if matches.opt_present("long") { - let long_options = try!(long()); + let long_options = long()?; if matches.opt_present("grid") { match other_options_scan() { @@ -178,7 +178,7 @@ impl View { } } - try!(long_options_scan()); + long_options_scan()?; other_options_scan() } @@ -232,8 +232,8 @@ impl TerminalWidth { impl Columns { fn deduce(matches: &getopts::Matches) -> Result { Ok(Columns { - size_format: try!(SizeFormat::deduce(matches)), - time_types: try!(TimeTypes::deduce(matches)), + size_format: SizeFormat::deduce(matches)?, + time_types: TimeTypes::deduce(matches)?, inode: matches.opt_present("inode"), links: matches.opt_present("links"), blocks: matches.opt_present("blocks"), diff --git a/src/output/details.rs b/src/output/details.rs index a8bdb7a1..ac925102 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -218,7 +218,7 @@ impl Details { // Then add files to the table and print it out. self.add_files_to_table(&mut table, files, 0); for cell in table.print_table() { - try!(writeln!(w, "{}", cell.strings())); + writeln!(w, "{}", cell.strings())?; } Ok(()) diff --git a/src/output/grid.rs b/src/output/grid.rs index 9daff075..b5342a18 100644 --- a/src/output/grid.rs +++ b/src/output/grid.rs @@ -48,7 +48,7 @@ impl Grid { else { // File names too long for a grid - drop down to just listing them! for file in files.iter() { - try!(writeln!(w, "{}", filename(file, &self.colours, false).strings())); + writeln!(w, "{}", filename(file, &self.colours, false).strings())?; } Ok(()) } diff --git a/src/output/lines.rs b/src/output/lines.rs index e5319303..668900e3 100644 --- a/src/output/lines.rs +++ b/src/output/lines.rs @@ -17,7 +17,7 @@ pub struct Lines { impl Lines { pub fn view(&self, files: Vec, w: &mut W) -> IOResult<()> { for file in files { - try!(writeln!(w, "{}", ANSIStrings(&filename(&file, &self.colours, true)))); + writeln!(w, "{}", ANSIStrings(&filename(&file, &self.colours, true)))?; } Ok(()) }