Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAddrInfo: raise exception if no AddrInfo returned #408

Merged
merged 1 commit into from
Jun 9, 2019

Conversation

endgame
Copy link
Contributor

@endgame endgame commented Jun 4, 2019

Closes #407.

POSIX1 requires getaddrinfo(3) to return at least one addrinfo:

Upon successful return of getaddrinfo(), the location to which res
points shall refer to a linked list of addrinfo structures, each of
which shall specify a socket address and information for use in
creating a socket with which to use that socket address. The list
shall include at least one addrinfo structure.

This behaviour is also specified by the manpages for Linux2,
OpenBSD3, FreeBSD4, NetBSD5 and macOS6, and most example code
just calls head (or equivalent) on the returned list anyway.

It would have been nice to return NonEmpty here, but that was vetoed
for backwards-compatibility reasons.

POSIX[1] requires getaddrinfo(3) to return at least one addrinfo:

> Upon successful return of getaddrinfo(), the location to which res
> points shall refer to a linked list of addrinfo structures, each of
> which shall specify a socket address and information for use in
> creating a socket with which to use that socket address. The list
> shall include at least one addrinfo structure.

This behaviour is also specified by the manpages for Linux[2],
OpenBSD[3], FreeBSD[4], NetBSD[5] and macOS[6], and most example code
just calls `head` (or equivalent) on the returned list anyway.

It would have been nice to return `NonEmpty` here, but that was vetoed
for backwards-compatibility reasons.

[1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
[2]: https://linux.die.net/man/3/getaddrinfo
[3]: https://man.openbsd.org/getaddrinfo.3
[4]: http://nixdoc.net/man-pages/FreeBSD/man4/man3/getaddrinfo.3.html
[5]: http://nixdoc.net/man-pages/NetBSD/man3/getaddrinfo.3.html
[6]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getaddrinfo.3.html
@kazu-yamamoto
Copy link
Collaborator

@eborden Would you suggest what kind of exception is proper for this case?

@kazu-yamamoto kazu-yamamoto self-assigned this Jun 6, 2019
@kazu-yamamoto kazu-yamamoto requested a review from eborden June 6, 2019 00:36
@kazu-yamamoto
Copy link
Collaborator

@eborden In general, I like this PR. We should check the type of exception.

@eborden
Copy link
Collaborator

eborden commented Jun 7, 2019

@kazu-yamamoto NoSuchThing makes sense to me. As much as I'd love to use proper extensible exceptions, I think that ship has currently sailed for network. I'd rather be consistent with IOError than have 1 or 2 custom exceptions floating around. Refactoring the exception landscape in network would be a major version bump and maybe even an epoch like 4.x.

@eborden eborden merged commit 2b0b774 into haskell:master Jun 9, 2019
@endgame endgame deleted the getaddrinfo-nonempty-result branch January 14, 2020 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does getAddrInfo return IO (NonEmpty AddrInfo)?
3 participants