Class Mongo::Error::OperationFailure
In: lib/mongo/error/operation_failure.rb
Parent: Error

Raised when an operation fails for some reason.

@since 2.0.0

Methods

Included Modules

SdamErrorDetection

Constants

WRITE_RETRY_ERRORS = [ {:code_name => 'InterruptedAtShutdown', :code => 11600}, {:code_name => 'InterruptedDueToStepDown', :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   Error codes and code names that should result in a failing write being retried.

@since 2.6.0 @api private

WRITE_RETRY_MESSAGES = [ 'not master', 'node is recovering', ].freeze   These are magic error messages that could indicate a master change.

@since 2.4.2 @api private

RETRY_MESSAGES = 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'   These are magic error messages that could indicate a cluster reconfiguration behind a mongos.

@since 2.1.1 @api private

CHANGE_STREAM_NOT_RESUME_ERRORS = [ {:code_name => 'CappedPositionLost', :code => 136}, {:code_name => 'CursorKilled', :code => 237}, {:code_name => 'Interrupted', :code => 11601}, ].freeze   Error codes and code names that should result in a failing getMore command on a change stream NOT being resumed.

@since 2.6.0 @api private

CHANGE_STREAM_RESUME_MESSAGES = WRITE_RETRY_MESSAGES   Change stream can be resumed when these error messages are encountered.

@since 2.6.0 @api private

Attributes

code  [R]  @return [ Integer ] code The error code parsed from the document. @since 2.6.0
code_name  [R]  @return [ String ] code_name The error code name parsed from the document. @since 2.6.0

Public Class methods

Create the operation failure.

@example Create the error object

  OperationFailure.new(message, result)

@example Create the error object with a code and a code name

  OperationFailure.new(message, result, :code => code, :code_name => code_name)

@param [ String ] message The error message. @param [ Operation::Result ] result The result object. @param [ Hash ] options Additional parameters

@option options [ Integer ] :code Error code @option options [ String ] :code_name Error code name @option options [ Array<String> ] :labels The set of labels associated

  with the error

@option options [ true | false ] :wtimeout Whether the error is a wtimeout

@since 2.5.0, options added in 2.6.0

Public Instance methods

Can the change stream on which this error occurred be resumed, provided the operation that triggered this error was a getMore?

@example Is the error resumable for the change stream?

  error.change_stream_resumable?

@return [ true, false ] Whether the error is resumable.

@since 2.6.0

Can the read operation that caused the error be retried?

@example Is the error retryable?

  error.retryable?

@return [ true, false ] Whether the error is retryable.

@since 2.1.1

Can the write operation that caused the error be retried?

@example Is the error retryable for writes?

  error.write_retryable?

@return [ true, false ] Whether the error is retryable.

@since 2.4.2

Whether the error is a write concern timeout.

@return [ true | false ] Whether the error is a write concern timeout.

@since 2.7.1

[Validate]