Exception: Mongo::Error::OperationFailure

Inherits:
Mongo::Error
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/error/operation_failure.rb

Overview

Raised when an operation fails for some reason.

Since:

  • 2.0.0

Constant Summary

WRITE_RETRY_MESSAGES =

These are magic error messages that could indicate a master change.

Since:

  • 2.4.2

[
  'no master',
  'not master',
  'could not contact primary',
  'Not primary'
].freeze
RETRY_MESSAGES =

These are magic error messages that could indicate a cluster reconfiguration behind a mongos. We cannot check error codes as they change between versions, for example 15988 which has 2 completely different meanings between 2.4 and 3.0.

Since:

  • 2.1.1

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

Constants inherited from Mongo::Error

BAD_VALUE, CODE, CURSOR_NOT_FOUND, ERR, ERRMSG, ERROR, UNKNOWN_ERROR, WRITE_CONCERN_ERROR, WRITE_CONCERN_ERRORS, WRITE_ERRORS

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, result = nil) ⇒ OperationFailure

Create the operation failure.

param [ String ] message The error message. param [ Operation::Result ] result The result object.

Examples:

Create the error object

OperationFailure.new(message, result)

Since:

  • 2.5.0



88
89
90
91
# File 'lib/mongo/error/operation_failure.rb', line 88

def initialize(message = nil, result = nil)
  @result = result
  super(message)
end

Instance Method Details

#retryable?true, false

Can the read operation that caused the error be retried?

Examples:

Is the error retryable?

error.retryable?

Returns:

  • (true, false)

    If the error is retryable.

Since:

  • 2.1.1



63
64
65
# File 'lib/mongo/error/operation_failure.rb', line 63

def retryable?
  RETRY_MESSAGES.any?{ |m| message.include?(m) }
end

#write_retryable?true, false

Can the write operation that caused the error be retried?

Examples:

Is the error retryable for writes?

error.write_retryable?

Returns:

  • (true, false)

    If the error is retryable.

Since:

  • 2.4.2



75
76
77
# File 'lib/mongo/error/operation_failure.rb', line 75

def write_retryable?
  WRITE_RETRY_MESSAGES.any? { |m| message.include?(m) }
end