From 46d4ebff4c32f135406aff9489c6859f9bec549c Mon Sep 17 00:00:00 2001 From: clint Date: Tue, 7 Nov 2023 18:02:13 -0500 Subject: [PATCH] expand: remove crash! macro --- src/uu/expand/src/expand.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 9294d1a8f..71d03a49a 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -15,7 +15,7 @@ use std::str::from_utf8; use unicode_width::UnicodeWidthChar; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; -use uucore::{crash, format_usage, help_about, help_usage}; +use uucore::{format_usage, help_about, help_usage}; const ABOUT: &str = help_about!("expand.md"); const USAGE: &str = help_usage!("expand.md"); @@ -308,16 +308,13 @@ pub fn uu_app() -> Command { ) } -fn open(path: &str) -> BufReader> { +fn open(path: &str) -> std::io::Result>> { let file_buf; if path == "-" { - BufReader::new(Box::new(stdin()) as Box) + Ok(BufReader::new(Box::new(stdin()) as Box)) } else { - file_buf = match File::open(path) { - Ok(a) => a, - Err(e) => crash!(1, "{}: {}\n", path.maybe_quote(), e), - }; - BufReader::new(Box::new(file_buf) as Box) + file_buf = File::open(path)?; + Ok(BufReader::new(Box::new(file_buf) as Box)) } } @@ -378,7 +375,7 @@ fn expand(options: &Options) -> std::io::Result<()> { let mut buf = Vec::new(); for file in &options.files { - let mut fh = open(file); + let mut fh = open(file)?; while match fh.read_until(b'\n', &mut buf) { Ok(s) => s > 0,