Exception: Mongo::Error::OperationFailure
- Inherits:
-
Mongo::Error
- Object
- StandardError
- Mongo::Error
- Mongo::Error::OperationFailure
- Extended by:
- Forwardable
- Includes:
- SdamErrorDetection
- Defined in:
- build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb
Overview
Raised when an operation fails for some reason.
Constant Summary collapse
- WRITE_RETRY_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 write being retried.
[ {: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}, ].freeze
- WRITE_RETRY_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.
These are magic error messages that could indicate a master change.
[ 'not master', 'node is recovering', ].freeze
- RETRY_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.
These are magic error messages that could indicate a cluster reconfiguration behind a mongos.
WRITE_RETRY_MESSAGES + [ 'transport error', 'socket exception', "can't connect", 'connect failed', 'error querying', 'could not get last error', 'connection attempt failed', 'interrupted at shutdown', 'unknown replica set', 'dbclient error communicating with server' ].freeze
- 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.
WRITE_RETRY_MESSAGES
Constants included from SdamErrorDetection
SdamErrorDetection::NODE_RECOVERING_CODES, SdamErrorDetection::NODE_SHUTTING_DOWN_CODES, SdamErrorDetection::NOT_MASTER_CODES
Constants inherited from Mongo::Error
BAD_VALUE, CODE, CURSOR_NOT_FOUND, ERR, ERRMSG, ERROR, TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_ERROR, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL, WRITE_CONCERN_ERROR, WRITE_CONCERN_ERRORS, WRITE_ERRORS
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.
-
#document ⇒ BSON::Document | nil
readonly
The server-returned error document.
-
#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.
Attributes included from Notable
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 = {}) ⇒ OperationFailure
constructor
Create the operation failure.
-
#max_time_ms_expired? ⇒ true | false
Whether the error is MaxTimeMSExpired.
- #retryable? ⇒ true, false deprecated Deprecated.
-
#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.
-
#write_retryable? ⇒ true, false
Whether the error is a retryable error according to the modern retryable reads and retryable writes specifications.
-
#wtimeout? ⇒ true | false
Whether the error is a write concern timeout.
Methods included from SdamErrorDetection
#node_recovering?, #node_shutting_down?, #not_master?
Methods inherited from Mongo::Error
#add_label, #label?, #labels, #write_concern_error_label?, #write_concern_error_labels
Methods included from Notable
Constructor Details
#initialize(message = nil, result = nil, options = {}) ⇒ OperationFailure
Create the operation failure.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 263 def initialize( = nil, result = nil, = {}) super() @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 |
Instance Attribute Details
#code ⇒ Integer (readonly)
Returns The error code parsed from the document.
88 89 90 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 88 def code @code end |
#code_name ⇒ String (readonly)
Returns The error code name parsed from the document.
93 94 95 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 93 def code_name @code_name end |
#document ⇒ BSON::Document | nil (readonly)
Returns The server-returned error document.
230 231 232 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 230 def document @document end |
#server_message ⇒ String (readonly)
Returns The server-returned error message parsed from the response.
99 100 101 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 99 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.
219 220 221 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 219 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.
225 226 227 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 225 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.
213 214 215 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 213 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?
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 176 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.
83 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 83 def_delegator :@result, :connection_description |
#max_time_ms_expired? ⇒ true | false
Whether the error is MaxTimeMSExpired.
292 293 294 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 292 def max_time_ms_expired? code == 50 # MaxTimeMSExpired end |
#retryable? ⇒ true, false
Whether the error is a retryable error according to the legacy read retry logic.
108 109 110 111 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 108 def retryable? write_retryable? || code.nil? && RETRY_MESSAGES.any?{ |m| .include?(m) } 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.
303 304 305 306 307 308 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 303 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.
205 206 207 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 205 def write_concern_error? !!@write_concern_error_document end |
#write_retryable? ⇒ true, false
Whether the error is a retryable error according to the modern retryable reads and retryable writes specifications.
This method is also used by the legacy retryable write logic to determine whether an error is a retryable one.
122 123 124 125 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 122 def write_retryable? write_retryable_code? || code.nil? && WRITE_RETRY_MESSAGES.any? { |m| .include?(m) } end |
#wtimeout? ⇒ true | false
Whether the error is a write concern timeout.
283 284 285 |
# File 'build/ruby-driver-v2.17/lib/mongo/error/operation_failure.rb', line 283 def wtimeout? @wtimeout end |