Skip to content

Commit 8ee9203

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

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/mongo/error/operation_failure.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ def initialize(message = nil, result = nil, options = {})
182182
@code = options[:code]
183183
@code_name = options[:code_name]
184184
super(message)
185+
186+
err_doc = result.send(:first_document)
187+
if err_doc['errorLabels']
188+
err_doc['errorLabels'].each do |label|
189+
add_label(label)
190+
end
191+
end
185192
end
186193
end
187194
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)