ruby-changes:37032
From: hsbt <ko1@a...>
Date: Sat, 3 Jan 2015 10:39:16 +0900 (JST)
Subject: [ruby-changes:37032] hsbt:r49113 (trunk): * lib/net/http.rb: More descriptive error message when net/http fails
hsbt 2015-01-03 10:38:59 +0900 (Sat, 03 Jan 2015) New Revision: 49113 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49113 Log: * lib/net/http.rb: More descriptive error message when net/http fails to connect to a server. Patch by @xaviershay [fix GH-700] * test/net/http/test_http.rb: ditto. Modified files: trunk/ChangeLog trunk/lib/net/http.rb trunk/test/net/http/test_http.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49112) +++ ChangeLog (revision 49113) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jan 3 10:38:52 2015 SHIBATA Hiroshi <shibata.hiroshi@g...> + + * lib/net/http.rb: More descriptive error message when net/http fails + to connect to a server. Patch by @xaviershay [fix GH-700] + * test/net/http/test_http.rb: ditto. + Sat Jan 3 10:14:51 2015 SHIBATA Hiroshi <shibata.hiroshi@g...> * ext/openssl/ossl.h: Make `SSL_SESSION_cmp` use `CRYPTO_memcmp` Index: lib/net/http.rb =================================================================== --- lib/net/http.rb (revision 49112) +++ lib/net/http.rb (revision 49113) @@ -876,7 +876,12 @@ module Net #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L876 D "opening connection to #{conn_address}:#{conn_port}..." s = Timeout.timeout(@open_timeout, Net::OpenTimeout) { - TCPSocket.open(conn_address, conn_port, @local_host, @local_port) + begin + TCPSocket.open(conn_address, conn_port, @local_host, @local_port) + rescue => e + raise e, "Failed to open TCP connection to " + + "#{conn_address}:#{conn_port} (#{e.message})" + end } s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) D "opened" Index: test/net/http/test_http.rb =================================================================== --- test/net/http/test_http.rb (revision 49112) +++ test/net/http/test_http.rb (revision 49113) @@ -188,6 +188,15 @@ class TestNetHTTP < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_http.rb#L188 end end + def test_failure_message_includes_failed_domain_and_port + begin + Net::HTTP.get(URI.parse("http://doesnotexist.bogus")) + fail "should have raised" + rescue => e + assert_includes e.message, "doesnotexist.bogus:80" + end + end + end module TestNetHTTP_version_1_1_methods -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/