Exception: Mongo::Error::OperationFailure

Inherits:
Mongo::Error
  • Object
show all
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

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



60
61
62
# File 'lib/mongo/error/operation_failure.rb', line 60

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



72
73
74
# File 'lib/mongo/error/operation_failure.rb', line 72

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