@@ -517,18 +517,18 @@ open class Process: NSObject {
517
517
var modifiedPipes : [ ( handle: HANDLE , prevValue: DWORD ) ] = [ ]
518
518
defer { modifiedPipes. forEach { SetHandleInformation ( $0. handle, DWORD ( HANDLE_FLAG_INHERIT) , $0. prevValue) } }
519
519
520
- func deferReset( handle: HANDLE ) throws {
520
+ func deferReset( handle: HANDLE , description : String ) throws {
521
521
var handleInfo : DWORD = 0
522
522
guard GetHandleInformation ( handle, & handleInfo) else {
523
- throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false )
523
+ throw _NSErrorWithWindowsError ( GetLastError ( ) , reading: false , extraUserInfo : [ NSLocalizedFailureReasonErrorKey : " deferReset( \( handle ) , \( description ) ): GetHandleInformation failed " ] )
524
524
}
525
525
modifiedPipes. append ( ( handle: handle, prevValue: handleInfo & DWORD ( HANDLE_FLAG_INHERIT) ) )
526
526
}
527
527
528
528
switch standardInput {
529
529
case let pipe as Pipe :
530
530
siStartupInfo. hStdInput = pipe. fileHandleForReading. _handle
531
- try deferReset ( handle: pipe. fileHandleForWriting. _handle)
531
+ try deferReset ( handle: pipe. fileHandleForWriting. _handle, description : " standardInput as Pipe .fileHandleForReading " )
532
532
SetHandleInformation ( pipe. fileHandleForWriting. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 0 )
533
533
534
534
// nil or NullDevice maps to NUL
@@ -538,15 +538,15 @@ open class Process: NSObject {
538
538
539
539
case let handle as FileHandle :
540
540
siStartupInfo. hStdInput = handle. _handle
541
- try deferReset ( handle: handle. _handle)
541
+ try deferReset ( handle: handle. _handle, description : " standardInput as FileHandle " )
542
542
SetHandleInformation ( handle. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 1 )
543
543
default : break
544
544
}
545
545
546
546
switch standardOutput {
547
547
case let pipe as Pipe :
548
548
siStartupInfo. hStdOutput = pipe. fileHandleForWriting. _handle
549
- try deferReset ( handle: pipe. fileHandleForReading. _handle)
549
+ try deferReset ( handle: pipe. fileHandleForReading. _handle, description : " standardOutput as Pipe .fileHandleForReading " )
550
550
SetHandleInformation ( pipe. fileHandleForReading. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 0 )
551
551
552
552
// nil or NullDevice maps to NUL
@@ -556,15 +556,15 @@ open class Process: NSObject {
556
556
557
557
case let handle as FileHandle :
558
558
siStartupInfo. hStdOutput = handle. _handle
559
- try deferReset ( handle: handle. _handle)
559
+ try deferReset ( handle: handle. _handle, description : " standardOutput as FileHandle " )
560
560
SetHandleInformation ( handle. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 1 )
561
561
default : break
562
562
}
563
563
564
564
switch standardError {
565
565
case let pipe as Pipe :
566
566
siStartupInfo. hStdError = pipe. fileHandleForWriting. _handle
567
- try deferReset ( handle: pipe. fileHandleForReading. _handle)
567
+ try deferReset ( handle: pipe. fileHandleForReading. _handle, description : " standardError as Pipe .fileHandleForReading " )
568
568
SetHandleInformation ( pipe. fileHandleForReading. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 0 )
569
569
570
570
// nil or NullDevice maps to NUL
@@ -574,7 +574,7 @@ open class Process: NSObject {
574
574
575
575
case let handle as FileHandle :
576
576
siStartupInfo. hStdError = handle. _handle
577
- try deferReset ( handle: handle. _handle)
577
+ try deferReset ( handle: handle. _handle, description : " standardError as FileHandle " )
578
578
SetHandleInformation ( handle. _handle, DWORD ( HANDLE_FLAG_INHERIT) , 1 )
579
579
default : break
580
580
}
@@ -674,9 +674,9 @@ open class Process: NSObject {
674
674
// ENOENT, we intercept the error to match the POSIX
675
675
// behaviour
676
676
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 ) " ] )
678
678
}
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 ) " ] )
680
680
}
681
681
}
682
682
}
0 commit comments