From a96f86710eaabe5ae8c235ca537ad5b156884fc9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 24 Nov 2021 21:15:39 +0100 Subject: =?UTF-8?q?don=E2=80=99t=20panic!()=20on=20open(2)=20failure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2dee9ca..d0014a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -545,18 +545,18 @@ impl Palette pub fn from_file(fname: &Path) -> io::Result { - /* Check if file exists - */ - let file = match std::fs::File::open(&fname) { - Err(e) => { - panic!("failed to open {} as file ({})", fname.display(), e) - }, - Ok(f) => f, - }; + let file = std::fs::File::open(&fname).map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!( + "failed to open palette specification {}: {}", + fname.display(), + e + ), + ) + })?; let mut reader = std::io::BufReader::new(file); - /* Parse scheme file - */ Self::from_buffered_reader(&mut reader) } -- cgit v1.2.3