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

Improve exception error messages for getAddrInfo and getNameInfo #289

Merged
merged 1 commit into from
Dec 31, 2017

Conversation

MaxGabriel
Copy link
Contributor

@develop7 ran into an issue with yesod devel (yesodweb/yesod#1471) and got the following error message:

devel.hs: Network.Socket.getAddrInfo: does not exist (Name or service not known)

It would be useful to have a more detailed error message to aid in debugging this exception. The new message looks like this:

> getAddrInfo Nothing (Just "127.0.0.1") (Just "foo")
*** Exception: Network.Socket.getAddrInfo (called with preferred socket type/protocol: Nothing, host name: Just "127.0.0.1", service name: Just "foo"): does not exist (nodename nor servname provided, or not known)

I think a more verbose error message is well worth it, especially since these kind of lower-level, underlying issues can be hard to debug.

(I added a similar error message for getNameInfo since it was right there)

@develop7 ran into an issue with `yesod devel` (yesodweb/yesod#1471) and got the following error message:

```
devel.hs: Network.Socket.getAddrInfo: does not exist (Name or service not known)
```

It would be useful to have a more detailed error message to aid in debugging this exception. The new message looks like this:

```
> getAddrInfo Nothing (Just "127.0.0.1") (Just "foo")
*** Exception: Network.Socket.getAddrInfo (called with preferred socket type/protocol: Nothing, host name: Just "127.0.0.1", service name: Just "foo"): does not exist (nodename nor servname provided, or not known)
```

I think a more verbose error message is well worth it, especially since these kind of lower-level, underlying issues can be hard to debug.

(I added a similar error message for `getNameInfo` since it was right there)
Copy link
Collaborator

@eborden eborden left a comment

Choose a reason for hiding this comment

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

These look great! Thanks.

@eborden eborden merged commit 3e779b2 into haskell:master Dec 31, 2017
@MaxGabriel
Copy link
Contributor Author

Thanks @eborden! Didn’t realize you did stackage and network, thanks for all your work :)

@MaxGabriel
Copy link
Contributor Author

Oh wait I'm confusing you with bergmark, sorry :P

@develop7
Copy link

There's an issue with this PR: the defaultHints initializes the addrAddress and addrCanonName of AddrInfo with undefined which explodes like this:

Devel application launched: http://localhost:3000
devel.hs: Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
  undefined, called at Network/Socket.hsc:1407:40 in network-2.6.3.2-Elf6Dxkfz0iKjb1zv5eBTP:Network.Socket

@MaxGabriel
Copy link
Contributor Author

Oh hm, I assumed that correct usage of the library was to set the undefined fields to something sensible first

@MaxGabriel
Copy link
Contributor Author

I see that the docs for defaultHints say:

-- | Default hints for address lookup with 'getAddrInfo'.  The values
-- of the 'addrAddress' and 'addrCanonName' fields are 'undefined',
-- and are never inspected by 'getAddrInfo'.
--

So it sounds like expected usage is for those fields to be undefined. I can think of a couple workarounds:

  1. Print only the fields that are not undefined by default
  2. Don’t print the AddrInfo field

I’d probably implement (1) unless you have further advice on this @eborden

@eborden
Copy link
Collaborator

eborden commented Dec 31, 2017

(1) Seems like a reasonable approach. Do you plan to open a PR?

@MaxGabriel
Copy link
Contributor Author

Yeah, but I’m going skiing for a few days so might be a bit

@develop7 develop7 mentioned this pull request Jan 2, 2018
kazu-yamamoto pushed a commit to kazu-yamamoto/network that referenced this pull request Jan 9, 2018
kazu-yamamoto added a commit to kazu-yamamoto/network that referenced this pull request Jan 9, 2018
kazu-yamamoto pushed a commit to kazu-yamamoto/network that referenced this pull request Jan 9, 2018
kazu-yamamoto added a commit to kazu-yamamoto/network that referenced this pull request Jan 9, 2018
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.

3 participants