haskell / haskell/network

The getNameInfo API is a little strange

Open
#416 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
366
Forks
210
Avg merge
22h 38m
Merged PRs (30d)
5

Description

`getNameInfo` has the ability to report a name resolution error by means of returning `Nothing`. When the `NI_NAMEREQD` flag is not set, resolution will never fail because the function simply returns the IP address we were trying to look up. When `NI_NAMEREQD` is set, however, the function is supposed to fail when that address can't be resolved. Curiously enough, that failure is communicated through an `IOException` instead of simply returning `Nothing`! This is really surprising to me and I find myself writing code like

getNameInfo [NI_NAMEREQD] True False localAddr `catchIO` \_ -> return (Nothing,Nothing)

most of the time.

Is there any particular reason why an `IOException` is used to communicate a perfectly legitimate result of that function call?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.