Module: Mongo::Error::OperationFailure::Family
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Instance Chain:
|
|
Defined in: | lib/mongo/error/operation_failure.rb |
Overview
Implements the behavior for an ::Mongo::Error::OperationFailure
error. Other errors (e.g. ::Mongo::Error::ServerTimeoutError
) may also implement this, so that they may be recognized and treated as ::Mongo::Error::OperationFailure
errors.
Constant Summary
-
CHANGE_STREAM_RESUME_ERRORS =
Internal use only
::Mongo::Error
codes and code names that should result in a failing getMore command on a change stream NOT being resumed.[ {code_name: 'HostUnreachable', code: 6}, {code_name: 'HostNotFound', code: 7}, {code_name: 'NetworkTimeout', code: 89}, {code_name: 'ShutdownInProgress', code: 91}, {code_name: 'PrimarySteppedDown', code: 189}, {code_name: 'ExceededTimeLimit', code: 262}, {code_name: 'SocketException', code: 9001}, {code_name: 'NotMaster', code: 10107}, {code_name: 'InterruptedAtShutdown', code: 11600}, {code_name: 'InterruptedDueToReplStateChange', code: 11602}, {code_name: 'NotPrimaryNoSecondaryOk', code: 13435}, {code_name: 'NotMasterOrSecondary', code: 13436}, {code_name: 'StaleShardVersion', code: 63}, {code_name: 'FailedToSatisfyReadPreference', code: 133}, {code_name: 'StaleEpoch', code: 150}, {code_name: 'RetryChangeStream', code: 234}, {code_name: 'StaleConfig', code: 13388}, ].freeze
-
CHANGE_STREAM_RESUME_MESSAGES =
Internal use only
Change stream can be resumed when these error messages are encountered.
ReadWriteRetryable::WRITE_RETRY_MESSAGES
::Mongo::Error::SdamErrorDetection
- Included
NODE_RECOVERING_CODES, NODE_SHUTTING_DOWN_CODES, NOT_MASTER_CODES
::Mongo::Error::ReadWriteRetryable
- Included
Instance Attribute Summary
-
#change_stream_resumable? ⇒ true, false
readonly
Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?
- #code ⇒ Integer readonly
- #code_name ⇒ String readonly
- #details ⇒ String | nil readonly
- #document ⇒ BSON::Document | nil readonly
-
#max_time_ms_expired? ⇒ true | false
readonly
Whether the error is MaxTimeMSExpired.
- #result ⇒ Operation::Result readonly Internal use only Internal use only
- #server_message ⇒ String readonly
-
#unsupported_retryable_write? ⇒ true | false
readonly
Whether the error is caused by an attempted retryable write on a storage engine that does not support retryable writes.
- #write_concern_error? ⇒ true | false readonly
- #write_concern_error_code ⇒ Integer | nil readonly
- #write_concern_error_code_name ⇒ String | nil readonly
-
#write_concern_error_document ⇒ Hash | nil
readonly
Returns the write concern error document as it was reported by the server, if any.
-
#wtimeout? ⇒ true | false
readonly
Whether the error is a write concern timeout.
- #change_stream_resumable_code? ⇒ Boolean readonly private
::Mongo::Error::ReadWriteRetryable
- Included
#retryable? | Whether the error is a retryable error according to the legacy read retry logic. |
#write_retryable? | Whether the error is a retryable error according to the modern retryable reads and retryable writes specifications. |
#write_retryable_code? |
::Mongo::Error::SdamErrorDetection
- Included
#node_recovering? | Whether the error is a “node is recovering” error, or one of its variants. |
#node_shutting_down? | Whether the error is a “node is shutting down” type error. |
#not_master? | Whether the error is a “not master” error, or one of its variants. |
Instance Method Summary
- #connection_description ⇒ Server::Description Internal use only
-
#initialize(message = nil, result = nil, options = {})
Create the operation failure.
-
#append_details(message, details) ⇒ String
private
Append the details to the message.
-
#retrieve_details(document) ⇒ Hash | nil
private
Retrieve the details from a document.
Instance Attribute Details
#change_stream_resumable? ⇒ true
, false
(readonly)
Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?
# File 'lib/mongo/error/operation_failure.rb', line 97
def change_stream_resumable? if @result && @result.is_a?(Mongo::Operation::GetMore::Result) # CursorNotFound exceptions are always resumable because the server # is not aware of the cursor id, and thus cannot determine if # the cursor is a change stream and cannot add the # ResumableChangeStreamError label. return true if code == 43 # Connection description is not populated for unacknowledged writes. if connection_description.max_wire_version >= 9 label?('ResumableChangeStreamError') else change_stream_resumable_code? end else false end end
#change_stream_resumable_code? ⇒ Boolean
(readonly, private)
# File 'lib/mongo/error/operation_failure.rb', line 116
def change_stream_resumable_code? CHANGE_STREAM_RESUME_ERRORS.any? { |e| e[:code] == code } end
#code ⇒ Integer
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 44
attr_reader :code
#code_name ⇒ String
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 49
attr_reader :code_name
#details ⇒ String
| nil
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 152
attr_reader :details
#document ⇒ BSON::Document
| nil
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 157
attr_reader :document
#max_time_ms_expired? ⇒ true
| false
(readonly)
Whether the error is MaxTimeMSExpired.
# File 'lib/mongo/error/operation_failure.rb', line 218
def max_time_ms_expired? code == 50 # MaxTimeMSExpired end
#result ⇒ Operation::Result (readonly)
# File 'lib/mongo/error/operation_failure.rb', line 162
attr_reader :result
#server_message ⇒ String
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 55
attr_reader :
#unsupported_retryable_write? ⇒ true
| false
(readonly)
Whether the error is caused by an attempted retryable write on a storage engine that does not support retryable writes.
retryable write on a storage engine that does not support retryable writes.
# File 'lib/mongo/error/operation_failure.rb', line 229
def unsupported_retryable_write? # code 20 is IllegalOperation. # Note that the document is expected to be a BSON::Document, thus # either having string keys or providing indifferent access. code == 20 && &.start_with?("Transaction numbers") || false end
#write_concern_error? ⇒ true
| false
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 126
def write_concern_error? !!@write_concern_error_document end
#write_concern_error_code ⇒ Integer
| nil
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 140
attr_reader :write_concern_error_code
#write_concern_error_code_name ⇒ String
| nil
(readonly)
# File 'lib/mongo/error/operation_failure.rb', line 146
attr_reader :write_concern_error_code_name
#write_concern_error_document ⇒ Hash
| nil
(readonly)
Returns the write concern error document as it was reported by the server, if any.
# File 'lib/mongo/error/operation_failure.rb', line 134
attr_reader :write_concern_error_document
#wtimeout? ⇒ true
| false
(readonly)
Whether the error is a write concern timeout.
# File 'lib/mongo/error/operation_failure.rb', line 209
def wtimeout? @wtimeout end
Instance Method Details
#append_details(message, details) ⇒ String
(private)
Append the details to the message
#connection_description ⇒ Server::Description
# File 'lib/mongo/error/operation_failure.rb', line 39
def_delegator :@result, :connection_description
#initialize(message = nil, result = nil, options = {})
Create the operation failure.
# File 'lib/mongo/error/operation_failure.rb', line 187
def initialize( = nil, result = nil, = {}) @details = retrieve_details( [:document]) super(append_details(, @details)) @result = result @code = [:code] @code_name = [:code_name] @write_concern_error_document = [:write_concern_error_document] @write_concern_error_code = [:write_concern_error_code] @write_concern_error_code_name = [:write_concern_error_code_name] @write_concern_error_labels = [:write_concern_error_labels] || [] @labels = [:labels] || [] @wtimeout = !! [:wtimeout] @document = [:document] @server_message = [: ] end
#retrieve_details(document) ⇒ Hash
| nil
(private)
Retrieve the details from a document