Module: Mongo::Error::OperationFailure::Family
- Extended by:
- Forwardable
- Includes:
- ReadWriteRetryable, SdamErrorDetection
- Included in:
- Mongo::Error::OperationFailure, ServerTimeoutError
- Defined in:
- lib/mongo/error/operation_failure.rb
Overview
Implements the behavior for an OperationFailure error. Other errors (e.g. ServerTimeoutError) may also implement this, so that they may be recognized and treated as OperationFailure errors.
Constant Summary collapse
- CHANGE_STREAM_RESUME_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Change stream can be resumed when these error messages are encountered.
ReadWriteRetryable::WRITE_RETRY_MESSAGES
Constants included from ReadWriteRetryable
ReadWriteRetryable::RETRY_MESSAGES, ReadWriteRetryable::WRITE_RETRY_ERRORS, ReadWriteRetryable::WRITE_RETRY_MESSAGES
Constants included from SdamErrorDetection
SdamErrorDetection::NODE_RECOVERING_CODES, SdamErrorDetection::NODE_SHUTTING_DOWN_CODES, SdamErrorDetection::NOT_MASTER_CODES
Instance Attribute Summary collapse
-
#code ⇒ Integer
readonly
The error code parsed from the document.
-
#code_name ⇒ String
readonly
The error code name parsed from the document.
-
#details ⇒ String | nil
readonly
The details of the error.
-
#document ⇒ BSON::Document | nil
readonly
The server-returned error document.
-
#result ⇒ Operation::Result
readonly
private
The result object for the operation.
-
#server_message ⇒ String
readonly
The server-returned error message parsed from the response.
-
#write_concern_error_code ⇒ Integer | nil
readonly
The error code for the write concern error, if a write concern error is present and has a code.
-
#write_concern_error_code_name ⇒ String | nil
readonly
The code name for the write concern error, if a write concern error is present and has a code name.
-
#write_concern_error_document ⇒ Hash | nil
readonly
Returns the write concern error document as it was reported by the server, if any.
Instance Method Summary collapse
-
#change_stream_resumable? ⇒ true, false
Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?.
-
#connection_description ⇒ Server::Description
private
Server description of the server that the operation that this exception refers to was performed on.
-
#initialize(message = nil, result = nil, options = {}) ⇒ Object
Create the operation failure.
-
#max_time_ms_expired? ⇒ true | false
Whether the error is MaxTimeMSExpired.
-
#unsupported_retryable_write? ⇒ true | false
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
Whether the failure includes a write concern error.
-
#wtimeout? ⇒ true | false
Whether the error is a write concern timeout.
Methods included from ReadWriteRetryable
#retryable?, #write_retryable?
Methods included from SdamErrorDetection
#node_recovering?, #node_shutting_down?, #not_master?
Instance Attribute Details
#code ⇒ Integer (readonly)
Returns The error code parsed from the document.
44 45 46 |
# File 'lib/mongo/error/operation_failure.rb', line 44 def code @code end |
#code_name ⇒ String (readonly)
Returns The error code name parsed from the document.
49 50 51 |
# File 'lib/mongo/error/operation_failure.rb', line 49 def code_name @code_name end |
#details ⇒ String | nil (readonly)
152 153 154 |
# File 'lib/mongo/error/operation_failure.rb', line 152 def details @details end |
#document ⇒ BSON::Document | nil (readonly)
Returns The server-returned error document.
157 158 159 |
# File 'lib/mongo/error/operation_failure.rb', line 157 def document @document end |
#result ⇒ Operation::Result (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the result object for the operation.
162 163 164 |
# File 'lib/mongo/error/operation_failure.rb', line 162 def result @result end |
#server_message ⇒ String (readonly)
Returns The server-returned error message parsed from the response.
55 56 57 |
# File 'lib/mongo/error/operation_failure.rb', line 55 def @server_message end |
#write_concern_error_code ⇒ Integer | nil (readonly)
Returns The error code for the write concern error, if a write concern error is present and has a code.
140 141 142 |
# File 'lib/mongo/error/operation_failure.rb', line 140 def write_concern_error_code @write_concern_error_code end |
#write_concern_error_code_name ⇒ String | nil (readonly)
Returns The code name for the write concern error, if a write concern error is present and has a code name.
146 147 148 |
# File 'lib/mongo/error/operation_failure.rb', line 146 def write_concern_error_code_name @write_concern_error_code_name end |
#write_concern_error_document ⇒ Hash | nil (readonly)
Returns the write concern error document as it was reported by the server, if any.
134 135 136 |
# File 'lib/mongo/error/operation_failure.rb', line 134 def write_concern_error_document @write_concern_error_document end |
Instance Method Details
#change_stream_resumable? ⇒ true, false
Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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 |
#connection_description ⇒ Server::Description
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Server description of the server that the operation that this exception refers to was performed on.
39 |
# File 'lib/mongo/error/operation_failure.rb', line 39 def_delegator :@result, :connection_description |
#initialize(message = nil, result = nil, options = {}) ⇒ Object
Create the operation failure.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# 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 = [:server_message] end |
#max_time_ms_expired? ⇒ true | false
Whether the error is MaxTimeMSExpired.
218 219 220 |
# File 'lib/mongo/error/operation_failure.rb', line 218 def max_time_ms_expired? code == 50 # MaxTimeMSExpired end |
#unsupported_retryable_write? ⇒ true | false
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.
229 230 231 232 233 234 |
# 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
Returns Whether the failure includes a write concern error. A failure may have a top level error and a write concern error or either one of the two.
126 127 128 |
# File 'lib/mongo/error/operation_failure.rb', line 126 def write_concern_error? !!@write_concern_error_document end |
#wtimeout? ⇒ true | false
Whether the error is a write concern timeout.
209 210 211 |
# File 'lib/mongo/error/operation_failure.rb', line 209 def wtimeout? @wtimeout end |