Skip to content

Commit 1bc1c33

Browse files
committed
Report error if file not found
1 parent 4902a1e commit 1bc1c33

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

aiscript-vm/src/vm/mod.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ impl Vm {
6363
}
6464

6565
pub fn run_file(&mut self, path: PathBuf) {
66-
let source = fs::read_to_string(path).unwrap();
67-
let source: &'static str = Box::leak(source.into_boxed_str());
68-
if let Err(VmError::CompileError) = self.compile(source) {
69-
std::process::exit(65);
70-
}
71-
if let Err(VmError::RuntimeError(err)) = self.interpret() {
72-
eprintln!("{err}");
73-
std::process::exit(70);
66+
match fs::read_to_string(&path) {
67+
Ok(source) => {
68+
let source: &'static str = Box::leak(source.into_boxed_str());
69+
if let Err(VmError::CompileError) = self.compile(source) {
70+
std::process::exit(65);
71+
}
72+
if let Err(VmError::RuntimeError(err)) = self.interpret() {
73+
eprintln!("{err}");
74+
std::process::exit(70);
75+
}
76+
}
77+
Err(err) => {
78+
eprintln!("Failed to read file '{}': {}", path.display(), err);
79+
std::process::exit(1);
80+
}
7481
}
7582
}
7683

0 commit comments

Comments
 (0)