Skip to content

Raise Net::LDAP::ConnectionRefusedError when new connection is refused. #213

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

Merged
merged 5 commits into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/ldap/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(server)
rescue SocketError
raise Net::LDAP::Error, "No such address or other socket error."
rescue Errno::ECONNREFUSED
raise Net::LDAP::Error, "Server #{server[:host]} refused connection on port #{server[:port]}."
raise Net::LDAP::ConnectionRefusedError, "Server #{server[:host]} refused connection on port #{server[:port]}."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I came to think no need to wrap Errno::ECONNREFUSED in this situation.
@mtodd @jch How do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I prefer not wrapping the error because Errno::ECONNREFUSED is more descriptive and appropriate. In fact, I'd rather we didn't rescue any wrap any of the errors in this block. However, this would be a breaking change in the API and require changes to the caller. We're not at 1.0, but this does seem like a nasty surprise. How do you feel about making a PR that shows deprecation warnings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do you feel about making a PR that shows deprecation warnings?

sounds great to me 👍

rescue Errno::EHOSTUNREACH => error
raise Net::LDAP::Error, "Host #{server[:host]} was unreachable (#{error.message})"
rescue Errno::ETIMEDOUT
Expand Down
7 changes: 7 additions & 0 deletions test/test_ldap_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ def test_blocked_port
end
end

def test_connection_refused
flexmock(TCPSocket).should_receive(:new).and_raise(Errno::ECONNREFUSED)
assert_raise Net::LDAP::ConnectionRefusedError do
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
end
end

def test_raises_unknown_exceptions
error = Class.new(StandardError)
flexmock(TCPSocket).should_receive(:new).and_raise(error)
Expand Down