Class: Mongo::Error::Parser
- Inherits:
-
Object
- Object
- Mongo::Error::Parser
- Includes:
- SdamErrorDetection
- Defined in:
- lib/mongo/error/parser.rb
Overview
Class for parsing the various forms that errors can come in from MongoDB command responses.
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
Code The error code parsed from the document.
-
#code_name ⇒ String
readonly
Code_name The error code name parsed from the document.
-
#document ⇒ BSON::Document
readonly
Document The returned document.
-
#labels ⇒ Array<String>
readonly
Labels The set of labels associated with the error.
-
#message ⇒ String
readonly
Message The error message parsed from the document.
-
#replies ⇒ Array<Protocol::Message>
readonly
Replies The message replies.
- #wtimeout ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(document, replies = nil, options = nil) ⇒ Parser
constructor
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.
Methods included from SdamErrorDetection
#node_recovering?, #node_shutting_down?, #not_master?
Constructor Details
#initialize(document, replies = nil, options = nil) ⇒ Parser
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.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mongo/error/parser.rb', line 94 def initialize(document, replies = nil, = nil) @document = document || {} @replies = replies = if .dup else {} end.freeze parse! end |
Instance Attribute Details
#code ⇒ Integer (readonly)
Returns code The error code parsed from the document.
60 61 62 |
# File 'lib/mongo/error/parser.rb', line 60 def code @code end |
#code_name ⇒ String (readonly)
Returns code_name The error code name parsed from the document.
64 65 66 |
# File 'lib/mongo/error/parser.rb', line 64 def code_name @code_name end |
#document ⇒ BSON::Document (readonly)
Returns document The returned document.
50 51 52 |
# File 'lib/mongo/error/parser.rb', line 50 def document @document end |
#labels ⇒ Array<String> (readonly)
Returns labels The set of labels associated with the error.
68 69 70 |
# File 'lib/mongo/error/parser.rb', line 68 def labels @labels end |
#message ⇒ String (readonly)
Returns message The error message parsed from the document.
53 54 55 |
# File 'lib/mongo/error/parser.rb', line 53 def end |
#replies ⇒ Array<Protocol::Message> (readonly)
Returns replies The message replies.
56 57 58 |
# File 'lib/mongo/error/parser.rb', line 56 def replies @replies 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.
71 72 73 |
# File 'lib/mongo/error/parser.rb', line 71 def wtimeout @wtimeout 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.
111 112 113 |
# File 'lib/mongo/error/parser.rb', line 111 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 |