From 1b9356cca2e1b2d03f5f36c50fd20077e0a99d15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Tue, 25 Apr 2023 10:41:26 +0100
Subject: [PATCH] chore: improved error handling

---
 src/cpu.rs  | 7 ++++++-
 src/util.rs | 5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/cpu.rs b/src/cpu.rs
index fa102c2b..4c938244 100644
--- a/src/cpu.rs
+++ b/src/cpu.rs
@@ -280,7 +280,12 @@ impl Cpu {
         }
 
         #[cfg(feature = "cpulog")]
-        println!("[0x{:04x}] {}\t({} cycles)", self.pc - 1, inst_str, inst_time);
+        println!(
+            "[0x{:04x}] {}\t({} cycles)",
+            self.pc - 1,
+            inst_str,
+            inst_time
+        );
 
         #[cfg(feature = "secure")]
         if self.mmu.boot_active() && self.pc - 1 > 0x08ff {
diff --git a/src/util.rs b/src/util.rs
index 177b9b67..96776eec 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -3,7 +3,10 @@ use std::{cell::RefCell, fs::File, io::Read, rc::Rc};
 pub type SharedMut<T> = Rc<RefCell<T>>;
 
 pub fn read_file(path: &str) -> Vec<u8> {
-    let mut file = File::open(path).unwrap();
+    let mut file = match File::open(path) {
+        Ok(file) => file,
+        Err(_) => panic!("Failed to open file: {}", path),
+    };
     let mut data = Vec::new();
     file.read_to_end(&mut data).unwrap();
     data
-- 
GitLab