Skip to content

Conversation

@axelandersson
Copy link
Contributor

Motivation:

ChannelError and NIOConnectionError should conform CustomStringConvertible so that these errors can be easily logged.

As discussed in #3222.

Modifications:

Added conformance to ChannelError and wrote error messages for all cases.

Added conformance to NIOConnectionError.

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Thanks for opening this @axelandersson -- I left some feedback inline.


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.

extension NIOConnectionError: CustomStringConvertible {
public var description: String {
if let dnsError = (dnsAError ?? dnsAAAAError) {
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.

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.

Comment on lines 81 to 85
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.

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label May 6, 2025
@axelandersson axelandersson requested a review from glbrntt May 6, 2025 19:24
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Thank you!

@glbrntt glbrntt enabled auto-merge (squash) May 7, 2025 10:16
@glbrntt glbrntt merged commit 960dcfb into apple:main May 7, 2025
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants