Skip to content

Add getaddrinfo and getnameinfo returning GaiError - #657

Draft
kazu-yamamoto wants to merge 7 commits into
haskell:masterfrom
kazu-yamamoto:gai-error
Draft

kazu-yamamoto wants to merge 7 commits into
haskell:masterfrom
kazu-yamamoto:gai-error

Conversation

@kazu-yamamoto

Copy link
Copy Markdown
Collaborator

For #635. A draft while the naming is discussed there.

  • GaiError is abstract: the EAI_* patterns, EAI_SYSTEM carrying its Errno, and gaiErrorCode. A code an OS lacks (only Windows lacks any: EAI_ADDRFAMILY, EAI_OVERFLOW, EAI_SYSTEM) gets its own value that no OS returns.
  • gaiErrorString is pure: an English table (glibc's wording), the errno description for EAI_SYSTEM, and the Winsock table for unknown codes on Windows.
  • getaddrinfo and getnameinfo (with NameInfoQuery) return Either GaiError. errno is read right after the call.
  • getAddrInfo and getNameInfo are built on them, and change in three ways:
    • EAI_SYSTEM is thrown from its errno (ioe_errno and the errno's IOErrorType), not as NoSuchThing "System error".
    • EAI_AGAIN is ResourceExhausted, as EAGAIN is.
    • Messages come from the table, so macOS's wording becomes glibc's.
  • The local helpers which would shadow the new names are renamed.

Tested locally on Linux, macOS and Windows (WinIO).

🤖 Generated with Claude Code

kazu-yamamoto added a commit to kazu-yamamoto/network that referenced this pull request Nov 19, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@vdukhovni vdukhovni left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM.

Possible tweak in the error message, if preferred.

Comment thread Network/Socket/Info.hsc Outdated
, ", service name: "
, maybe "Nothing" show service
, ")"
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If those Nothing strings are distracting placeholders, rather the deliberate detail, one could write:

message = case catMaybes [
    ("preferred socket type/protocol: " ++) . show <$> hints
  , (", host name: " ++) . show <$> node
  , (", service name: " ++) . show <$> service
  ] of
  [] -> "Network.Socket.getAddrInfo"
  xs -> "Network.Socket.getAddrInfo (called with" ++ fold xs ++ ")"

Comment thread Network/Socket/Info.hsc
, ", socket address: "
, show addr
, ")"
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here, unless the Nothing placeholders are preferred to eliding these when not specified.

kazu-yamamoto and others added 7 commits November 20, 2026 18:21
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kazu-yamamoto

Copy link
Copy Markdown
Collaborator Author

Thanks for the review, and no worries about the timing.

I took the suggestion for getAddrInfo, with one change. As written, the separators go wrong: with no hints the message starts "called with, host name: ...", and with hints it reads "called withpreferred ...". So each part now carries no separator, and they are joined with intercalate ", ":

Network.Socket.getAddrInfo (called with host name: "no-such.invalid", service name: "80"): does not exist (Name or service not known)

When no argument is given, the message is just "Network.Socket.getAddrInfo".

getNameInfo's message is unchanged: it has no Maybe arguments. It shows the flags, the two Bools and the address.

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.

2 participants