Preserve getaddrinfo error code in SocketAddressError#3558
Open
thisismanan wants to merge 1 commit intoapple:mainfrom
Open
Preserve getaddrinfo error code in SocketAddressError#3558thisismanan wants to merge 1 commit intoapple:mainfrom
thisismanan wants to merge 1 commit intoapple:mainfrom
Conversation
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.
Author
|
Hey @Lukasa, just checking if you've had a chance to look at this. Happy to make any changes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As observed by @weissi #3382
Motivation:
When
getaddrinfofails, SwiftNIO throwsSocketAddressError.unknownwhich discards the error code. This makes it impossible for callers todistinguish between different failure reasons (e.g.,
EAI_NONAMEvsEAI_AGAIN), which is needed for retry logic and diagnostics.Modifications:
SocketAddressError.UnknownHoststruct that carrieshost,port,errorCode(fromgetaddrinfo), anderrorDescription(fromgai_strerror).SocketAddress.makeAddressResolvingHostandGetaddrinfoResolverto throw/fail with the new error type on both POSIX and Windows paths.testGetaddrinfoErrorCodeIsPreservedto verify the error code is captured.Result:
Callers can now inspect the
getaddrinfoerror code when host resolution fails, enabling more specific error handling. Resolves #3382Questions for reviewer
Should
case unknown(host:port:)be deprecated? — This enum case is no longer thrown after this PR. Callers catching.unknownwill silently stop matching. Should I add@available(*, deprecated, renamed: "UnknownHost")to provide a migration path?Should the doc comment on
makeAddressResolvingHostbe updated? — The- Throws:line still referencesSocketAddressError.unknowninstead of the newSocketAddressError.UnknownHost.