lib/mongo/operation/shared/response_handling.rb
# Adds error labels to exceptions raised in the yielded to block,
# which should perform MongoDB operations and raise Mongo::Errors on
# failure. This method handles network errors (Error::SocketError)
# and server-side errors (Error::OperationFailure); it does not
# handle server selection errors (Error::NoServerAvailable), for which
# labels are added in the server selection code.
#
# @param [ Mongo::Server::Connection ] connection The connection on which
#   the operation is performed.
# @param [ Mongo::Operation::Context ] context The operation context.
Adds error labels to exceptions raised in the yielded to block,
which should perform MongoDB operations and raise Mongo::Errors on
failure.
Adds error labels to exceptions raised in the yielded to block which should perform MongoDB operations and raise Mongo :: Errors on failure .
def add_error_labels(connection, context)
        begin
          yield
        rescue Mongo::Error::SocketError => e
          if context.in_transaction? && !context.committing_transaction?
            e.add_label('TransientTransactionError')
          end
          if context.committing_transaction?
            e.add_label('UnknownTransactionCommitResult')
          end
          maybe_add_retryable_write_error_label!(e, connection, context)
          raise e
        rescue Mongo::Error::SocketTimeoutError => e
          maybe_add_retryable_write_error_label!(e, connection, context)
          raise e
        rescue Mongo::Error::OperationFailure => e
          if context.committing_transaction?
            if e.write_retryable? || e.wtimeout? || (e.write_concern_error? &&
                !Session::UNLABELED_WRITE_CONCERN_CODES.include?(e.write_concern_error_code)
            ) || e.max_time_ms_expired?
              e.add_label('UnknownTransactionCommitResult')
            end
          end
          maybe_add_retryable_write_error_label!(e, connection, context)
          raise e
        end
      end
def add_error_labels ( connection , context ) begin yield rescue Mongo :: Error :: SocketError => e if context . in_transaction? && ! context . committing_transaction? e . add_label ( 'TransientTransactionError' ) end if context . committing_transaction? e . add_label ( 'UnknownTransactionCommitResult' ) end maybe_add_retryable_write_error_label! ( e , connection , context ) raise e rescue Mongo :: Error :: SocketTimeoutError => e maybe_add_retryable_write_error_label! ( e , connection , context ) raise e rescue Mongo :: Error :: OperationFailure => e if context . committing_transaction? if e . write_retryable? || e . wtimeout? || ( e . write_concern_error? && ! Session :: UNLABELED_WRITE_CONCERN_CODES . include? ( e . write_concern_error_code ) ) || e . max_time_ms_expired? e . add_label ( 'UnknownTransactionCommitResult' ) end end maybe_add_retryable_write_error_label! ( e , connection , context ) raise e end end
Adds error labels to exceptions raised in the yielded to block,
which should perform MongoDB operations and raise Mongo::Errors on
failure.
Adds error labels to exceptions raised in the yielded to block which should perform MongoDB operations and raise Mongo :: Errors on failure .
connection
<not_specific>
context
<not_specific>
<not_specific>
context The operation context.
context The operation context .