Parser — Documentation by YARD 0.9.37 (original) (raw)

Class: Mongo::Error::ParserPrivate

Overview

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

Class for parsing the various forms that errors can come in from MongoDB command responses.

The errors can be reported by the server in a number of ways:

Note that writeErrors do not have codeName fields - they just provide codes and messages. writeConcernErrors may similarly not provide code names.

Constant Summary

Constants included from SdamErrorDetection

SdamErrorDetection::NODE_RECOVERING_CODES, SdamErrorDetection::NODE_SHUTTING_DOWN_CODES, SdamErrorDetection::NOT_MASTER_CODES

Instance Attribute Summary collapse

Class Method Summarycollapse

Instance Method Summarycollapse

Methods included from SdamErrorDetection

#node_recovering?, #node_shutting_down?, #not_master?

Constructor Details

#initialize(document, replies = nil, options = nil) ⇒ Parser

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.

Create the new parser with the returned document.

In legacy mode, the code and codeName fields of the document are not examined because the status (ok: 1) is not part of the document and there is no way to distinguish successful from failed responses using the document itself, and a successful response may legitimately have { code: 123, codeName: ‘foo’ } as the contents of a user-inserted document. The legacy server versions do not fill out code nor codeName thus not reading them does not lose information.

| 122 123 124 125 126 127 128 129 130 131 | # File 'lib/mongo/error/parser.rb', line 122 def initialize(document, = nil, options = nil) @document = document || {} @replies = @options = if options options.dup else {} end.freeze parse! end | | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

Instance Attribute Details

#code ⇒ Integer

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.

Returns The error code parsed from the document.

88 89 90 # File 'lib/mongo/error/parser.rb', line 88 def code @code end

#code_name ⇒ String

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.

Returns The error code name parsed from the document.

92 93 94 # File 'lib/mongo/error/parser.rb', line 92 def code_name @code_name end

#document ⇒ BSON::Document

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.

Returns The returned document.

73 74 75 # File 'lib/mongo/error/parser.rb', line 73 def document @document end

#labels ⇒ Array

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.

Returns The set of labels associated with the error.

96 97 98 # File 'lib/mongo/error/parser.rb', line 96 def labels @labels end

#message ⇒ String

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.

Returns The full error message to be used in the raised exception.

77 78 79 # File 'lib/mongo/error/parser.rb', line 77 def message @message end

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.

Returns The message replies.

84 85 86 # File 'lib/mongo/error/parser.rb', line 84 def @replies end

#server_message ⇒ String

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.

Returns The server-returned error message parsed from the response.

81 82 83 # File 'lib/mongo/error/parser.rb', line 81 def server_message @server_message end

#wtimeout ⇒ 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.

99 100 101 # File 'lib/mongo/error/parser.rb', line 99 def wtimeout @wtimeout end

Class Method Details

.build_message(code: nil, code_name: nil, message: nil) ⇒ 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.

177 178 179 180 181 182 183 184 185 186 187 188 189 190 # File 'lib/mongo/error/parser.rb', line 177 def build_message(code: nil, code_name: nil, message: nil) if code_name && code "[#{code}:#{code_name}]: #{message}" elsif code_name "[#{code_name}]: #{message}" elsif code "[#{code}]: #{message}" else message end end

Instance Method Details

#write_concern_error? ⇒ true | false

Returns Whether the document includes a write concern error. A failure may have a top level error and a write concern error or either one of the two.

139 140 141 # File 'lib/mongo/error/parser.rb', line 139 def write_concern_error? !!write_concern_error_document end

#write_concern_error_code ⇒ Integer | nil

Returns The error code for the write concern error, if a write concern error is present and has a code.

157 158 159 # File 'lib/mongo/error/parser.rb', line 157 def write_concern_error_code write_concern_error_document && write_concern_error_document['code'] end

#write_concern_error_code_name ⇒ String | nil

Returns The code name for the write concern error, if a write concern error is present and has a code name.

166 167 168 # File 'lib/mongo/error/parser.rb', line 166 def write_concern_error_code_name write_concern_error_document && write_concern_error_document['codeName'] end

#write_concern_error_document ⇒ Hash | nil

Returns the write concern error document as it was reported by the server, if any.

148 149 150 # File 'lib/mongo/error/parser.rb', line 148 def write_concern_error_document document['writeConcernError'] end

#write_concern_error_labels ⇒ Array | nil

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.

write concern error, if there is a write concern error present.

172 173 174 # File 'lib/mongo/error/parser.rb', line 172 def write_concern_error_labels write_concern_error_document && write_concern_error_document['errorLabels'] end