Skip to content

Commit cb7e86b

Browse files
authored
Merge pull request #2263 from compnerd/i-have-made-a-grave-error
Improve Windows error handling
2 parents d79181b + 2677e70 commit cb7e86b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Foundation/FileHandle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ open class FileHandle : NSObject {
378378
while bytesRemaining > 0 {
379379
var bytesWritten: DWORD = 0
380380
if !WriteFile(handle, buf.advanced(by: length - bytesRemaining), DWORD(bytesRemaining), &bytesWritten, nil) {
381-
throw _NSErrorWithErrno(Int32(GetLastError()), reading: false, path: nil)
381+
throw _NSErrorWithWindowsError(GetLastError(), reading: false)
382382
}
383383
if bytesWritten == 0 {
384-
throw _NSErrorWithErrno(Int32(GetLastError()), reading: false, path: nil)
384+
throw _NSErrorWithWindowsError(GetLastError(), reading: false)
385385
}
386386
bytesRemaining -= Int(bytesWritten)
387387
}

Foundation/Process.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,15 @@ open class Process: NSObject {
503503
DWORD(CREATE_UNICODE_ENVIRONMENT), UnsafeMutableRawPointer(mutating: wszEnvironment),
504504
wszCurrentDirectory,
505505
&siStartupInfo, &piProcessInfo) {
506-
throw NSError(domain: _NSWindowsErrorDomain, code: Int(GetLastError()))
506+
throw _NSErrorWithWindowsError(GetLastError(), reading: false)
507507
}
508508
}
509509
}
510510
}
511511

512512
self.processHandle = piProcessInfo.hProcess
513513
if !CloseHandle(piProcessInfo.hThread) {
514-
throw NSError(domain: _NSWindowsErrorDomain, code: Int(GetLastError()))
514+
throw _NSErrorWithWindowsError(GetLastError(), reading: false)
515515
}
516516

517517
if let pipe = standardInput as? Pipe {

0 commit comments

Comments
 (0)