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.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mongo/error/parser.rb', line 85 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.
62 63 64 |
# File 'lib/mongo/error/parser.rb', line 62 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.
66 67 68 |
# File 'lib/mongo/error/parser.rb', line 66 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.
47 48 49 |
# File 'lib/mongo/error/parser.rb', line 47 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.
70 71 72 |
# File 'lib/mongo/error/parser.rb', line 70 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.
51 52 53 |
# File 'lib/mongo/error/parser.rb', line 51 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.
58 59 60 |
# File 'lib/mongo/error/parser.rb', line 58 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.
55 56 57 |
# File 'lib/mongo/error/parser.rb', line 55 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.
73 74 75 |
# File 'lib/mongo/error/parser.rb', line 73 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.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/mongo/error/parser.rb', line 140 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.
102 103 104 |
# File 'lib/mongo/error/parser.rb', line 102 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.
120 121 122 |
# File 'lib/mongo/error/parser.rb', line 120 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.
129 130 131 |
# File 'lib/mongo/error/parser.rb', line 129 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.
111 112 113 |
# File 'lib/mongo/error/parser.rb', line 111 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.
135 136 137 |
# File 'lib/mongo/error/parser.rb', line 135 def write_concern_error_labels write_concern_error_document && write_concern_error_document['errorLabels'] end |