File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ use std::result;
19
19
use thiserror:: Error ;
20
20
21
21
/// The error type for ttrpc.
22
- #[ derive( Error , Debug , Clone ) ]
22
+ #[ derive( Error , Debug , Clone , PartialEq ) ]
23
23
pub enum Error {
24
24
#[ error( "socket err: {0}" ) ]
25
25
Socket ( String ) ,
Original file line number Diff line number Diff line change @@ -321,9 +321,14 @@ impl ClientConnection {
321
321
opts. read ( true )
322
322
. write ( true )
323
323
. custom_flags ( FILE_FLAG_OVERLAPPED ) ;
324
- let file = opts. open ( self . address . as_str ( ) ) ;
325
-
326
- return PipeConnection :: new ( file. unwrap ( ) . into_raw_handle ( ) as isize )
324
+ match opts. open ( self . address . as_str ( ) ) {
325
+ Ok ( file) => {
326
+ return PipeConnection :: new ( file. into_raw_handle ( ) as isize )
327
+ }
328
+ Err ( e) => {
329
+ return Err ( Error :: Windows ( e. raw_os_error ( ) . unwrap ( ) ) )
330
+ }
331
+ }
327
332
}
328
333
329
334
pub fn close_receiver ( & self ) -> Result < ( ) > {
@@ -336,3 +341,22 @@ impl ClientConnection {
336
341
Ok ( ( ) )
337
342
}
338
343
}
344
+
345
+ #[ cfg( test) ]
346
+ mod test {
347
+ use super :: * ;
348
+ use windows_sys:: Win32 :: Foundation :: ERROR_FILE_NOT_FOUND ;
349
+
350
+ #[ test]
351
+ fn test_pipe_connection ( ) {
352
+ let client = ClientConnection :: new ( "non_existent_pipe" ) ;
353
+ match client. get_pipe_connection ( ) {
354
+ Ok ( _) => {
355
+ assert ! ( false , "should not be able to get a connection to a non existent pipe" ) ;
356
+ }
357
+ Err ( e) => {
358
+ assert_eq ! ( e, Error :: Windows ( ERROR_FILE_NOT_FOUND as i32 ) ) ;
359
+ }
360
+ }
361
+ }
362
+ }
You can’t perform that action at this time.
0 commit comments