Project

General

Profile

Actions

Feature #13677

closed

Add more details to error "Name or service not known (SocketError)"

Added by dsbonev (Dimitar Bonev) over 6 years ago. Updated almost 5 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:81759]

Description

ruby version: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

ruby script:

require 'socket'
TCPSocket.new 'nonexistent.example.com', 80

Result: getaddrinfo: Name or service not known (SocketError)

Expected: getaddrinfo: Name or service not known for nonexistent.example.com (SocketError)

Why:
This will make it easier to resolve errors of this kind by just looking at the logged messages. It is common for production and non-production (development, test) code to connect to different hosts which can produce errors due to wrong configuration.
This change will make the ruby stdlib code more consistent as other methods already provide useful error information. Some examples:

host = 'nonexistent.example.com'; port = 80
Resolv.getaddress host # => Resolv::ResolvError: no address for nonexistent.example.com
Socket.getservbyname host # => SocketError: no such service nonexistent.example.com/tcp
Net::HTTP.get Struct.new(:hostname, :port, :scheme).new(host, port, 'http') # => SocketError: Failed to open TCP connection to nonexistent.example.com:80 (getaddrinfo: Name or service not known)

If this issue will be resolved, please add any useful information to the error message in addition to the host.

Updated by shevegen (Robert A. Heiler) over 6 years ago

In general I agree that error messages should be as useful as possible.

(By the way, I think if you indent ruby code here in the bug tracker with four space tokens
on the left side aka ' ', colouring will be enabled. Would make it easier for others to
read it... let me try it).

host = 'nonexistent.example.com'; port = 80
Resolv.getaddress host # => Resolv::ResolvError: no address for nonexistent.example.com
Socket.getservbyname host # => SocketError: no such service nonexistent.example.com/tcp
Net::HTTP.get Struct.new(:hostname, :port, :scheme).new(host, port, 'http') # => SocketError: Failed to open TCP connection to nonexistent.example.com:80 (getaddrinfo: Name or service not known)

Edit: Oops not quite ... only indents to the left side as blockquote or so...

    host = 'nonexistent.example.com'; port = 80
    Resolv.getaddress host # => Resolv::ResolvError: no address for nonexistent.example.com
    Socket.getservbyname host # => SocketError: no such service nonexistent.example.com/tcp
    Net::HTTP.get Struct.new(:hostname, :port, :scheme).new(host, port, 'http') # => SocketError: Failed to open TCP connection to nonexistent.example.com:80 (getaddrinfo: Name or service not known)

Guess one has to prefix via "~~~ ruby" and end with "~~~" or just use the buttons.

Actions #2

Updated by dsbonev (Dimitar Bonev) over 6 years ago

  • Description updated (diff)

Updated by akr (Akira Tanaka) over 6 years ago

It sounds fine.

Actions #4

Updated by akr (Akira Tanaka) over 6 years ago

  • Status changed from Open to Feedback

Updated by shyouhei (Shyouhei Urabe) over 6 years ago

The proposed functionality sounds fine but no one currently have spare time to implement this; patch welcomed.

Updated by microweb10 (Julian Herrero) almost 5 years ago

shyouhei (Shyouhei Urabe) wrote:

The proposed functionality sounds fine but no one currently have spare time to implement this; patch welcomed.

I would like to work on this one.

Updated by duerst (Martin Dürst) almost 5 years ago

microweb10 (Julian Herrero) wrote:

I would like to work on this one.

Please do, patches are always welcome.

Updated by microweb10 (Julian Herrero) almost 5 years ago

duerst (Martin Dürst) wrote:

Please do, patches are always welcome.

I never contributed to Ruby and I'm a bit lost on how to start. I'm more familiar with Open source contributions via PRs.

Could you please give me some pointers on how to start and where to start looking? Thanks in advance!

Updated by duerst (Martin Dürst) almost 5 years ago

microweb10 (Julian Herrero) wrote:

I never contributed to Ruby and I'm a bit lost on how to start. I'm more familiar with Open source contributions via PRs.

You can contribute PRs to Ruby on github: see https://github.com/ruby/ruby.

Could you please give me some pointers on how to start and where to start looking? Thanks in advance!

There is https://bugs.ruby-lang.org/projects/ruby/wiki/HowToContribute, and https://www.ruby-lang.org/en/community/ruby-core/.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0