summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-24 21:15:39 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-24 21:15:39 +0100
commita96f86710eaabe5ae8c235ca537ad5b156884fc9 (patch)
tree0d531c085989bf0f5b4a2aa134a7645297231041
parentb4aadcde1ccf9021f7f47b3d8453faa333850e76 (diff)
downloadvtcol-a96f86710eaabe5ae8c235ca537ad5b156884fc9.tar.gz
don’t panic!() on open(2) failure
-rw-r--r--src/lib.rs20
1 files 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<Self>
{
- /* 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)
}