mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
As observed by @weissi https://github.com/apple/swift-nio/issues/3382 ### Motivation: When `getaddrinfo` fails, SwiftNIO throws `SocketAddressError.unknown` which discards the error code. This makes it impossible for callers to distinguish between different failure reasons (e.g., `EAI_NONAME` vs `EAI_AGAIN`), which is needed for retry logic and diagnostics. ### Modifications: - Add `SocketAddressError.UnknownHost` struct that carries `host`, `port`, `errorCode` (from `getaddrinfo`), and `errorDescription` (from `gai_strerror`). - Update `SocketAddress.makeAddressResolvingHost` and `GetaddrinfoResolver` to throw/fail with the new error type on both POSIX and Windows paths. - Update existing test catch blocks to use the new error type. - Add `testGetaddrinfoErrorCodeIsPreserved` to verify the error code is captured. ### Result: Callers can now inspect the `getaddrinfo` error code when host resolution fails, enabling more specific error handling. Resolves https://github.com/apple/swift-nio/issues/3382 ### Questions for reviewer 1. **Should `case unknown(host:port:)` be deprecated?** — This enum case is no longer thrown after this PR. Callers catching `.unknown` will silently stop matching. Should I add `@available(*, deprecated, renamed: "UnknownHost")` to provide a migration path? 2. **Should the doc comment on `makeAddressResolvingHost` be updated?** — The `- Throws:` line still references `SocketAddressError.unknown` instead of the new `SocketAddressError.UnknownHost`. --------- Co-authored-by: Si Beaumont <beaumont@apple.com>