File tree Expand file tree Collapse file tree 1 file changed +15
-8
lines changed
Expand file tree Collapse file tree 1 file changed +15
-8
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments