@@ -517,18 +517,18 @@ open class Process: NSObject {
517517 var modifiedPipes : [ ( handle: HANDLE , prevValue: DWORD ) ] = [ ]
518518 defer { modifiedPipes. forEach { SetHandleInformation ( $0. handle, DWORD ( HANDLE_FLAG_INHERIT) , $0. prevValue) } }
519519
520- func deferReset( handle: HANDLE ) throws {
520+ func deferReset( handle: HANDLE , description : String ) throws {
521521 var handleInfo : DWORD = 0
522522 guard GetHandleInformation ( handle, & handleInfo) else {
523- throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
523+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false , extraUserInfo : [ NSLocalizedFailureReasonErrorKey : " deferReset( \( handle ) , \( description ) ): GetHandleInformation failed " ] )
524524 }
525525 modifiedPipes. append ( ( handle: handle, prevValue: handleInfo & DWORD ( HANDLE_FLAG_INHERIT) ) )
526526 }
527527
528528 switch standardInput {
529529 case let pipe as Pipe :
530530 siStartupInfo. hStdInput = pipe. fileHandleForReading. _handle
531- try deferReset ( handle: pipe. fileHandleForWriting. _handle)
531+ try deferReset ( handle: pipe. fileHandleForWriting. _handle, description : " standardInput as Pipe .fileHandleForReading " )
532532 SetHandleInformation ( pipe. fileHandleForWriting. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 0 )
533533
534534 // nil or NullDevice maps to NUL
@@ -538,15 +538,15 @@ open class Process: NSObject {
538538
539539 case let handle as FileHandle :
540540 siStartupInfo. hStdInput = handle. _handle
541- try deferReset ( handle: handle. _handle)
541+ try deferReset ( handle: handle. _handle, description : " standardInput as FileHandle " )
542542 SetHandleInformation ( handle. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 1 )
543543 default : break
544544 }
545545
546546 switch standardOutput {
547547 case let pipe as Pipe :
548548 siStartupInfo. hStdOutput = pipe. fileHandleForWriting. _handle
549- try deferReset ( handle: pipe. fileHandleForReading. _handle)
549+ try deferReset ( handle: pipe. fileHandleForReading. _handle, description : " standardOutput as Pipe .fileHandleForReading " )
550550 SetHandleInformation ( pipe. fileHandleForReading. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 0 )
551551
552552 // nil or NullDevice maps to NUL
@@ -556,15 +556,15 @@ open class Process: NSObject {
556556
557557 case let handle as FileHandle :
558558 siStartupInfo. hStdOutput = handle. _handle
559- try deferReset ( handle: handle. _handle)
559+ try deferReset ( handle: handle. _handle, description : " standardOutput as FileHandle " )
560560 SetHandleInformation ( handle. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 1 )
561561 default : break
562562 }
563563
564564 switch standardError {
565565 case let pipe as Pipe :
566566 siStartupInfo. hStdError = pipe. fileHandleForWriting. _handle
567- try deferReset ( handle: pipe. fileHandleForReading. _handle)
567+ try deferReset ( handle: pipe. fileHandleForReading. _handle, description : " standardError as Pipe .fileHandleForReading " )
568568 SetHandleInformation ( pipe. fileHandleForReading. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 0 )
569569
570570 // nil or NullDevice maps to NUL
@@ -574,7 +574,7 @@ open class Process: NSObject {
574574
575575 case let handle as FileHandle :
576576 siStartupInfo. hStdError = handle. _handle
577- try deferReset ( handle: handle. _handle)
577+ try deferReset ( handle: handle. _handle, description : " standardError as FileHandle " )
578578 SetHandleInformation ( handle. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 1 )
579579 default : break
580580 }
@@ -674,9 +674,9 @@ open class Process: NSObject {
674674 // ENOENT, we intercept the error to match the POSIX
675675 // behaviour
676676 if error == ERROR_DIRECTORY {
677- throw _NSErrorWithWindowsError ( DWORD ( ERROR_FILE_NOT_FOUND) , reading: true )
677+ throw _NSErrorWithWindowsError ( DWORD ( ERROR_FILE_NOT_FOUND) , reading: true , extraUserInfo : [ NSLocalizedFailureReasonErrorKey : " CreateProcessW(nil, \( quoteWindowsCommandLine ( command ) ) , nil, nil, true, CREATE_UNICODE_ENVIRONMENT, \( szEnvironment ) , \( workingDirectory ) , <ptr>, <ptr>) failed with \( error ) " ] )
678678 }
679- throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true )
679+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: true , extraUserInfo : [ NSLocalizedFailureReasonErrorKey : " CreateProcessW(nil, \( quoteWindowsCommandLine ( command ) ) , nil, nil, true, CREATE_UNICODE_ENVIRONMENT, \( szEnvironment ) , \( workingDirectory ) , <ptr>, <ptr>) failed with \( error ) " ] )
680680 }
681681 }
682682 }
0 commit comments