Class: Mongo::Error::Parser Private
- Inherits:
-
Object
- Object
- Mongo::Error::Parser
- Includes:
- SdamErrorDetection
- Defined in:
- lib/mongo/error/parser.rb
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:
-
ok:0 response indicates failure. In newer servers, code, codeName and errmsg fields should be set. In older servers some may not be set.
-
ok:1 response with a write concern error (writeConcernError top-level field). This indicates that the node responding successfully executed the request, but not enough other nodes successfully executed the request to satisfy the write concern.
-
ok:1 response with writeErrors top-level field. This can be obtained in a bulk write but also in a non-bulk write. In a non-bulk write there should be exactly one error in the writeErrors list. The case of multiple errors is handled by BulkWrite::Result.
-
ok:1 response with writeConcernErrors top-level field. This can only be obtained in a bulk write and is handled by BulkWrite::Result, not by this class.
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
-
#code ⇒ Integer
readonly
private
The error code parsed from the document.
-
#code_name ⇒ String
readonly
private
The error code name parsed from the document.
-
#document ⇒ BSON::Document
readonly
private
The returned document.
-
#labels ⇒ Array<String>
readonly
private
The set of labels associated with the error.
-
#message ⇒ String
readonly
private
The full error message to be used in the raised exception.
-
#replies ⇒ Array<Protocol::Message>
readonly
private
The message replies.
-
#server_message ⇒ String
readonly
private
The server-returned error message parsed from the response.
- #wtimeout ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(document, replies = nil, options = nil) ⇒ Parser
constructor
private
Create the new parser with the returned document.
-
#write_concern_error? ⇒ true | false
Whether the document includes a write concern error.
-
#write_concern_error_code ⇒ Integer | nil
The error code for the write concern error, if a write concern error is present and has a code.
-
#write_concern_error_code_name ⇒ String | nil
The code name for the write concern error, if a write concern error is present and has a code name.
-
#write_concern_error_document ⇒ Hash | nil
Returns the write concern error document as it was reported by the server, if any.
-
#write_concern_error_labels ⇒ Array<String> | nil
private
write concern error, if there is a write concern error present.
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, replies = nil, = nil) @document = document || {} @replies = replies @options = if .dup else {} end.freeze parse! end |
Instance Attribute Details
#code ⇒ Integer (readonly)
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 (readonly)
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 (readonly)
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<String> (readonly)
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 (readonly)
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 end |
#replies ⇒ Array<Protocol::Message> (readonly)
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 @replies end |
#server_message ⇒ String (readonly)
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 end |
#wtimeout ⇒ Object (readonly)
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 (code: nil, code_name: nil, message: nil) if code_name && code "[#{code}:#{code_name}]: #{}" elsif code_name # This surely should never happen, if there's a code name # there ought to also be the code provided. # Handle this case for completeness. "[#{code_name}]: #{}" elsif code "[#{code}]: #{}" else 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<String> | 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 |