Skip to content

Commit 9a0bcb1

Browse files
authored
RUBY-1391 Ruby driver returns generic OpenSSL error message rather than the actual one (#988)
1 parent 9789120 commit 9a0bcb1

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

lib/mongo/socket.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Socket
2929
# Error message for SSL related exceptions.
3030
#
3131
# @since 2.0.0
32-
SSL_ERROR = 'SSL handshake failed. MongoDB may not be configured with SSL support.'.freeze
32+
SSL_ERROR = 'MongoDB may not be configured with SSL support'.freeze
3333

3434
# Error message for timeouts on socket calls.
3535
#
@@ -284,9 +284,9 @@ def handle_errors
284284
rescue Errno::ETIMEDOUT
285285
raise Error::SocketTimeoutError, TIMEOUT_ERROR
286286
rescue IOError, SystemCallError => e
287-
raise Error::SocketError, e.message
288-
rescue OpenSSL::SSL::SSLError
289-
raise Error::SocketError, SSL_ERROR
287+
raise Error::SocketError, "#{e.class}: #{e}"
288+
rescue OpenSSL::SSL::SSLError => e
289+
raise Error::SocketError, "#{e.class}: #{e} (#{SSL_ERROR})"
290290
end
291291
end
292292
end

spec/mongo/socket/ssl_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@
561561

562562
it 'should raise EOFError' do
563563
expect { socket.readbyte }
564-
.to raise_error(Mongo::Error::SocketError).with_message("EOFError")
564+
.to raise_error(Mongo::Error::SocketError).with_message("EOFError: EOFError")
565565
end
566566
end
567567
end

spec/mongo/socket_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'lite_spec_helper'
2+
3+
describe Mongo::Socket do
4+
5+
let(:socket) do
6+
described_class.new(Socket::PF_INET)
7+
end
8+
9+
describe '#handle_errors' do
10+
it 'maps timeout exception' do
11+
expect do
12+
socket.send(:handle_errors) do
13+
raise Errno::ETIMEDOUT
14+
end
15+
end.to raise_error(Mongo::Error::SocketTimeoutError)
16+
end
17+
18+
it 'maps SystemCallError and preserves message' do
19+
expect do
20+
socket.send(:handle_errors) do
21+
raise SystemCallError.new('Test error', Errno::ENOMEDIUM::Errno)
22+
end
23+
end.to raise_error(Mongo::Error::SocketError, 'Errno::ENOMEDIUM: No medium found - Test error')
24+
end
25+
26+
it 'maps IOError and preserves message' do
27+
expect do
28+
socket.send(:handle_errors) do
29+
raise IOError.new('Test error')
30+
end
31+
end.to raise_error(Mongo::Error::SocketError, 'IOError: Test error')
32+
end
33+
34+
it 'maps SSLError and preserves message' do
35+
expect do
36+
socket.send(:handle_errors) do
37+
raise OpenSSL::SSL::SSLError.new('Test error')
38+
end
39+
end.to raise_error(Mongo::Error::SocketError, 'OpenSSL::SSL::SSLError: Test error (MongoDB may not be configured with SSL support)')
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)