Skip to content

Commit faaedaa

Browse files
committed
RUBY-1587 Properly handle error labels sent by server
1 parent 6f0a128 commit faaedaa

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/mongo/error/operation_failure.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ def initialize(message = nil, result = nil, options = {})
182182
@code = options[:code]
183183
@code_name = options[:code_name]
184184
super(message)
185+
186+
if result
187+
err_doc = result.send(:first_document)
188+
189+
if err_doc && err_doc['errorLabels']
190+
err_doc['errorLabels'].each do |label|
191+
add_label(label)
192+
end
193+
end
194+
end
185195
end
186196
end
187197
end

lib/mongo/operation/get_more/result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def cursor_document
5252
end
5353

5454
def first_document
55-
@first_document ||= reply.documents[0]
55+
@first_document ||= reply && reply.documents[0]
5656
end
5757
end
5858
end

spec/support/transactions/operation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ def execute(collection, session0, session1)
114114
{
115115
'errorCodeName' => err_doc['codeName'] || err_doc['writeConcernError']['codeName'],
116116
'errorContains' => e.message,
117-
'errorLabels' => (e.instance_variable_get(:@labels) || []) + (err_doc['errorLabels'] || [])
117+
'errorLabels' => e.instance_variable_get(:@labels)
118118
}
119119
rescue Mongo::Error => e
120120
{
121121
'errorContains' => e.message,
122-
'errorLabels' => e.instance_variable_get(:@labels) || []
122+
'errorLabels' => e.instance_variable_get(:@labels)
123123
}
124124
end
125125

0 commit comments

Comments
 (0)