Exception: Mongo::Error::OperationFailure
- Inherits:
-
Mongo::Error
- Object
- StandardError
- Mongo::Error
- Mongo::Error::OperationFailure
- Extended by:
- Forwardable
- Defined in:
- 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 => 'InterruptedAtShutdown', :code => 11600}, {:code_name => 'InterruptedDueToReplStateChange', :code => 11602}, {:code_name => 'NotMaster', :code => 10107}, {:code_name => 'NotMasterNoSlaveOk', :code => 13435}, {:code_name => 'NotMasterOrSecondary', :code => 13436}, {:code_name => 'PrimarySteppedDown', :code => 189}, {:code_name => 'ShutdownInProgress', :code => 91}, {:code_name => 'HostNotFound', :code => 7}, {:code_name => 'HostUnreachable', :code => 6}, {:code_name => 'NetworkTimeout', :code => 89}, {:code_name => 'SocketException', :code => 9001}, ].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_NOT_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 => 'CappedPositionLost', :code => 136}, {:code_name => 'CursorKilled', :code => 237}, {:code_name => 'Interrupted', :code => 11601}, ].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 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
Code The error code parsed from the document.
-
#code_name ⇒ String
readonly
Code_name The error code name parsed from the document.
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?.
-
#initialize(message = nil, result = nil, options = {}) ⇒ OperationFailure
constructor
Create the operation failure.
-
#retryable? ⇒ true, false
Can the read operation that caused the error be retried?.
-
#write_retryable? ⇒ true, false
Can the write operation that caused the error be retried?.
Methods inherited from Mongo::Error
Constructor Details
#initialize(message = nil, result = nil, options = {}) ⇒ OperationFailure
Create the operation failure.
180 181 182 183 184 185 186 |
# File 'lib/mongo/error/operation_failure.rb', line 180 def initialize( = nil, result = nil, = {}) @result = result @code = [:code] @code_name = [:code_name] @labels = [:labels] super() end |
Instance Attribute Details
#code ⇒ Integer (readonly)
Returns code The error code parsed from the document.
74 75 76 |
# File 'lib/mongo/error/operation_failure.rb', line 74 def code @code end |
#code_name ⇒ String (readonly)
Returns code_name The error code name parsed from the document.
78 79 80 |
# File 'lib/mongo/error/operation_failure.rb', line 78 def code_name @code_name 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?
141 142 143 144 145 146 147 148 |
# File 'lib/mongo/error/operation_failure.rb', line 141 def change_stream_resumable? if @result && @result.is_a?(Mongo::Operation::GetMore::Result) || change_stream_resumable_code? else false end end |
#retryable? ⇒ true, false
Can the read operation that caused the error be retried?
88 89 90 |
# File 'lib/mongo/error/operation_failure.rb', line 88 def retryable? RETRY_MESSAGES.any?{ |m| .include?(m) } end |
#write_retryable? ⇒ true, false
Can the write operation that caused the error be retried?
100 101 102 103 |
# File 'lib/mongo/error/operation_failure.rb', line 100 def write_retryable? WRITE_RETRY_MESSAGES.any? { |m| .include?(m) } || write_retryable_code? end |