File tree Expand file tree Collapse file tree 3 files changed +47
-5
lines changed Expand file tree Collapse file tree 3 files changed +47
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments