Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Sources/NIOCore/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,47 @@ extension ChannelError {

extension ChannelError: Equatable {}

extension ChannelError: CustomStringConvertible {
public var description: String {
switch self {
case .connectPending:
"Connect pending"
case let .connectTimeout(value):
"Connect timeout (\(value))"
case .operationUnsupported:
"Operation unsupported"
case .ioOnClosedChannel:
"I/O on closed channel"
case .alreadyClosed:
"Already closed"
case .outputClosed:
"Output closed"
case .inputClosed:
"Input closed"
case .eof:
"End of file"
case .writeMessageTooLarge:
"Write message too large"
case .writeHostUnreachable:
"Write host unreachable"
case .unknownLocalAddress:
"Unknown local address"
case .badMulticastGroupAddressFamily:
"Bad multicast group address family"
case .badInterfaceAddressFamily:
"Bad interface address family"
case let .illegalMulticastAddress(address):
"Illegal multicast address \(address)"
case let .multicastNotSupported(interface):
"Multicast not supported on interface \(interface)"
case .inappropriateOperationForState:
"Inappropriate operation for state"
case .unremovableHandler:
"Unremovable handler"
}
}
}

/// The removal of a `ChannelHandler` using `ChannelPipeline.removeHandler` has been attempted more than once.
public struct NIOAttemptedToRemoveHandlerMultipleTimesError: Error {}

Expand Down
22 changes: 22 additions & 0 deletions Sources/NIOPosix/HappyEyeballs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ public struct NIOConnectionError: Error {
}
}

extension NIOConnectionError: CustomStringConvertible {
public var description: String {
if let dnsError = (dnsAError ?? dnsAAAAError) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: coding style in NIO is to use explicit self:

Suggested change
if let dnsError = (dnsAError ?? dnsAAAAError) {
if let dnsError = (self.dnsAError ?? self.dnsAAAAError) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - updated.

return "DNS error: \(dnsError.localizedDescription)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localized description gives bad error messages unless the underlying error is an NSError:

Suggested change
return "DNS error: \(dnsError.localizedDescription)"
return "DNS error: \(dnsError)"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - updated.

}

if !connectionErrors.isEmpty {
let descriptions = connectionErrors.map {
if let channelError = $0.error as? ChannelError {
channelError.description
} else {
$0.error.localizedDescription
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do any casting here and avoid using localizedDescription. Just use String(describing: $0) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - updated.

}

return "Connection errors: \(descriptions.joined(separator: ", "))"
}

return "Unknown error"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can still hint that it's a connection error: e.g. "NIOConnectionError: unknown"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - updated.

}
}

/// A simple iterator that manages iterating over the possible targets.
///
/// This iterator knows how to merge together the A and AAAA records in a sensible way:
Expand Down