class Mongo::Error

Base error class for all Mongo related errors.

@since 2.0.0

Constants

BAD_VALUE

Constant for a bad value error.

@since 2.0.0

CODE

The error code field.

@since 2.0.0

CURSOR_NOT_FOUND

Constant for a Cursor not found error.

@since 2.2.3

ERR

An error field, MongoDB < 2.6

@since 2.0.0

ERRMSG

The standard error message field, MongoDB 3.0+

@since 2.0.0

ERROR

An error field, MongoDB < 2.4

@since 2.0.0

TRANSIENT_TRANSACTION_ERROR_LABEL

Error label describing errors that will likely not occur if a transaction is manually retried from the start.

@since 2.6.0 @deprecated

UNKNOWN_ERROR

Constant for an unknown error.

@since 2.0.0

UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL

Error label describing commitTransaction errors that may or may not occur again if a commit is manually retried by the user.

@since 2.6.0 @deprecated

WRITE_CONCERN_ERROR

The constant for a write concern error.

@since 2.0.0 @deprecated

WRITE_CONCERN_ERRORS

The constant for write concern errors.

@since 2.1.0 @deprecated

WRITE_ERRORS

The constant for the writeErrors array.

@since 2.0.0 @deprecated

Public Class Methods

new(msg = nil) click to toggle source
Calls superclass method
# File lib/mongo/error.rb, line 104
def initialize(msg = nil)
  super
  @labels = []
end

Public Instance Methods

add_label(label) click to toggle source

Adds the specified label to the error instance, if the label is not already in the set of labels.

@param [ String ] label The label to add.

@api private

# File lib/mongo/error.rb, line 141
def add_label(label)
  @labels << label unless label?(label)
end
change_stream_resumable?() click to toggle source

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

# File lib/mongo/error.rb, line 86
def change_stream_resumable?
  false
end
label?(label) click to toggle source

Does the error have the given label?

@example

error.label?(label)

@param [ String ] label The label to check if the error has.

@return [ true, false ] Whether the error has the given label.

@since 2.6.0

# File lib/mongo/error.rb, line 119
def label?(label)
  @labels.include?(label)
end
labels() click to toggle source

Gets the set of labels associated with the error.

@example

error.labels

@return [ Array ] The set of labels.

@since 2.7.0

# File lib/mongo/error.rb, line 131
def labels
  @labels.dup
end