File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed
src/hyperlight_host/src/sandbox Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -143,14 +143,18 @@ impl UninitializedSandbox {
143
143
log_build_details ( ) ;
144
144
145
145
// If the guest binary is a file make sure it exists
146
-
147
146
let guest_binary = match guest_binary {
148
147
GuestBinary :: FilePath ( binary_path) => {
149
- let path = Path :: new ( & binary_path) . canonicalize ( ) ?;
150
- path. try_exists ( ) ?;
151
- GuestBinary :: FilePath ( path. to_str ( ) . unwrap ( ) . to_string ( ) )
148
+ let path = Path :: new ( & binary_path)
149
+ . canonicalize ( )
150
+ . map_err ( |e| new_error ! ( "GuestBinary not found: '{}': {}" , binary_path, e) ) ?;
151
+ GuestBinary :: FilePath (
152
+ path. into_os_string ( )
153
+ . into_string ( )
154
+ . map_err ( |e| new_error ! ( "Error converting OsString to String: {:?}" , e) ) ?,
155
+ )
152
156
}
153
- GuestBinary :: Buffer ( buffer ) => GuestBinary :: Buffer ( buffer) ,
157
+ buffer @ GuestBinary :: Buffer ( _ ) => buffer,
154
158
} ;
155
159
156
160
let run_opts = sandbox_run_options. unwrap_or_default ( ) ;
@@ -1088,4 +1092,18 @@ mod tests {
1088
1092
assert_eq ! ( 0 , num_calls) ;
1089
1093
}
1090
1094
}
1095
+
1096
+ #[ test]
1097
+ fn test_invalid_path ( ) {
1098
+ let invalid_path = "some/path/that/does/not/exist" ;
1099
+ let sbox = UninitializedSandbox :: new (
1100
+ GuestBinary :: FilePath ( invalid_path. to_string ( ) ) ,
1101
+ None ,
1102
+ None ,
1103
+ None ,
1104
+ ) ;
1105
+ assert ! (
1106
+ matches!( sbox, Err ( e) if e. to_string( ) . contains( "GuestBinary not found: 'some/path/that/does/not/exist': No such file or directory (os error 2)" ) )
1107
+ ) ;
1108
+ }
1091
1109
}
You can’t perform that action at this time.
0 commit comments