Exception: Mongo::Error

Inherits:
StandardError
  • Object
show all
Includes:
Notable
Defined in:
lib/mongo/error.rb,
lib/mongo/error/parser.rb,
lib/mongo/error/notable.rb,
lib/mongo/error/auth_error.rb,
lib/mongo/error/lint_error.rb,
lib/mongo/error/invalid_uri.rb,
lib/mongo/error/invalid_file.rb,
lib/mongo/error/socket_error.rb,
lib/mongo/error/closed_stream.rb,
lib/mongo/error/invalid_nonce.rb,
lib/mongo/error/max_bson_size.rb,
lib/mongo/error/session_ended.rb,
lib/mongo/error/file_not_found.rb,
lib/mongo/error/no_srv_records.rb,
lib/mongo/error/handshake_error.rb,
lib/mongo/error/invalid_session.rb,
lib/mongo/error/write_retryable.rb,
lib/mongo/error/bulk_write_error.rb,
lib/mongo/error/extra_file_chunk.rb,
lib/mongo/error/invalid_document.rb,
lib/mongo/error/max_message_size.rb,
lib/mongo/error/missing_password.rb,
lib/mongo/error/multi_index_drop.rb,
lib/mongo/error/invalid_signature.rb,
lib/mongo/error/mismatched_domain.rb,
lib/mongo/error/operation_failure.rb,
lib/mongo/error/pool_closed_error.rb,
lib/mongo/error/invalid_txt_record.rb,
lib/mongo/error/missing_file_chunk.rb,
lib/mongo/error/invalid_read_option.rb,
lib/mongo/error/need_primary_server.rb,
lib/mongo/error/no_server_available.rb,
lib/mongo/error/unexpected_response.rb,
lib/mongo/error/missing_resume_token.rb,
lib/mongo/error/sdam_error_detection.rb,
lib/mongo/error/socket_timeout_error.rb,
lib/mongo/error/unknown_payload_type.rb,
lib/mongo/error/unsupported_features.rb,
lib/mongo/error/invalid_database_name.rb,
lib/mongo/error/invalid_file_revision.rb,
lib/mongo/error/invalid_min_pool_size.rb,
lib/mongo/error/invalid_write_concern.rb,
lib/mongo/error/unsupported_collation.rb,
lib/mongo/error/invalid_bulk_operation.rb,
lib/mongo/error/change_stream_resumable.rb,
lib/mongo/error/invalid_collection_name.rb,
lib/mongo/error/invalid_update_document.rb,
lib/mongo/error/unexpected_chunk_length.rb,
lib/mongo/error/invalid_application_name.rb,
lib/mongo/error/unsupported_message_type.rb,
lib/mongo/error/invalid_server_preference.rb,
lib/mongo/error/unsupported_array_filters.rb,
lib/mongo/error/invalid_bulk_operation_type.rb,
lib/mongo/error/connection_check_out_timeout.rb,
lib/mongo/error/failed_stringprep_validation.rb,
lib/mongo/error/insufficient_iteration_count.rb,
lib/mongo/error/invalid_replacement_document.rb,
lib/mongo/error/invalid_transaction_operation.rb,
lib/mongo/error/unchangeable_collection_option.rb

Overview

Base error class for all Mongo related errors.

Since:

  • 2.0.0

Defined Under Namespace

Modules: ChangeStreamResumable, Notable, SdamErrorDetection, WriteRetryable Classes: AuthError, BulkWriteError, ClosedStream, ConnectionCheckOutTimeout, ExtraFileChunk, FailedStringPrepValidation, FileNotFound, HandshakeError, InsufficientIterationCount, InvalidApplicationName, InvalidBulkOperation, InvalidBulkOperationType, InvalidCollectionName, InvalidDatabaseName, InvalidDocument, InvalidFile, InvalidFileRevision, InvalidMinPoolSize, InvalidNonce, InvalidReadOption, InvalidReplacementDocument, InvalidServerPreference, InvalidSession, InvalidSignature, InvalidTXTRecord, InvalidTransactionOperation, InvalidURI, InvalidUpdateDocument, InvalidWriteConcern, LintError, MaxBSONSize, MaxMessageSize, MismatchedDomain, MissingFileChunk, MissingPassword, MissingResumeToken, MultiIndexDrop, NeedPrimaryServer, NoSRVRecords, NoServerAvailable, OperationFailure, Parser, PoolClosedError, SessionEnded, SocketError, SocketTimeoutError, UnchangeableCollectionOption, UnexpectedChunkLength, UnexpectedResponse, UnknownPayloadType, UnsupportedArrayFilters, UnsupportedCollation, UnsupportedFeatures, UnsupportedMessageType

Constant Summary collapse

CODE =

The error code field.

Since:

  • 2.0.0

'code'.freeze
ERR =

An error field, MongoDB < 2.6

Since:

  • 2.0.0

'$err'.freeze
ERROR =

An error field, MongoDB < 2.4

Since:

  • 2.0.0

'err'.freeze
ERRMSG =

The standard error message field, MongoDB 3.0+

Since:

  • 2.0.0

'errmsg'.freeze
WRITE_ERRORS =
Deprecated.

The constant for the writeErrors array.

Since:

  • 2.0.0

'writeErrors'.freeze
WRITE_CONCERN_ERROR =
Deprecated.

The constant for a write concern error.

Since:

  • 2.0.0

'writeConcernError'.freeze
WRITE_CONCERN_ERRORS =
Deprecated.

The constant for write concern errors.

Since:

  • 2.1.0

'writeConcernErrors'.freeze
UNKNOWN_ERROR =

Constant for an unknown error.

Since:

  • 2.0.0

8.freeze
BAD_VALUE =

Constant for a bad value error.

Since:

  • 2.0.0

2.freeze
CURSOR_NOT_FOUND =

Constant for a Cursor not found error.

Since:

  • 2.2.3

'Cursor not found.'
UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL =
Deprecated.

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

'UnknownTransactionCommitResult'.freeze
TRANSIENT_TRANSACTION_ERROR_LABEL =
Deprecated.

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

Since:

  • 2.6.0

'TransientTransactionError'.freeze

Instance Method Summary collapse

Methods included from Notable

#add_note, #inspect, #message, #notes, #to_s

Constructor Details

#initialize(msg = nil) ⇒ Error

Returns a new instance of Error

Since:

  • 2.0.0



104
105
106
107
# File 'lib/mongo/error.rb', line 104

def initialize(msg = nil)
  super
  @labels = []
end

Instance Method Details

#add_label(label) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • label (String)

    The label to add.

Since:

  • 2.0.0



141
142
143
# File 'lib/mongo/error.rb', line 141

def add_label(label)
  @labels << label unless label?(label)
end

#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?

Examples:

Is the error resumable for the change stream?

error.change_stream_resumable?

Returns:

  • (true, false)

    Whether the error is resumable.

Since:

  • 2.6.0



86
87
88
# File 'lib/mongo/error.rb', line 86

def change_stream_resumable?
  false
end

#label?(label) ⇒ true, false

Does the error have the given label?

Examples:

error.label?(label)

Parameters:

  • label (String)

    The label to check if the error has.

Returns:

  • (true, false)

    Whether the error has the given label.

Since:

  • 2.6.0



119
120
121
# File 'lib/mongo/error.rb', line 119

def label?(label)
  @labels.include?(label)
end

#labelsArray

Gets the set of labels associated with the error.

Examples:

error.labels

Returns:

  • (Array)

    The set of labels.

Since:

  • 2.7.0



131
132
133
# File 'lib/mongo/error.rb', line 131

def labels
  @labels.dup
end