Skip to content

Commit

Permalink
Updated POSIXError
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Apr 19, 2019
1 parent 09467b6 commit 126fa2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 14 additions & 2 deletions Sources/BluetoothLinux/POSIXError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ internal extension POSIXError {
guard let code = POSIXErrorCode(rawValue: errno)
else { return nil }

return POSIXError(_nsError: NSPOSIXError(code))
return POSIXError(code)
}

init(_ code: POSIXErrorCode) {
self.init(_nsError: NSPOSIXError(code))
}
}

Expand All @@ -42,6 +46,14 @@ extension POSIXError: CustomStringConvertible {
}
}

#if os(macOS)
extension POSIXErrorCode {
public var description: String {
return rawValue.description
}
}
#endif

// MARK: - LocalizedError

extension POSIXError: LocalizedError {
Expand Down Expand Up @@ -82,7 +94,7 @@ internal final class NSPOSIXError: NSError {
}

override var description: String {
return "Error Domain=\(domain) Code=\(code) \"\(posixError.errorMessage)\""
return "\(posixError.errorMessage) (\(posixError))"
}
}

Expand Down
5 changes: 2 additions & 3 deletions Tests/BluetoothLinuxTests/BluetoothLinuxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class BluetoothLinuxTests: XCTestCase {

for (errorCode, string) in errors {

let error = POSIXError(_nsError: NSPOSIXError(errorCode))
let error = POSIXError(errorCode)

#if os(macOS) || swift(>=5.1)
// https://github.com/apple/swift-corelibs-foundation/pull/2113
Expand All @@ -48,8 +48,7 @@ final class BluetoothLinuxTests: XCTestCase {
#if os(macOS)
XCTAssertEqual(error.localizedDescription, string)
#endif
let errorDescription = "Error Domain=\(NSPOSIXErrorDomain) Code=\(errorCode.rawValue) \"\(string)\""
XCTAssertEqual("\(error)", errorDescription)
XCTAssert("\(error)".contains(string))
}
}
}
Expand Down

0 comments on commit 126fa2c

Please sign in to comment.