Skip to content

Commit 7a6b4d2

Browse files
Preprocess error type
1 parent b01734d commit 7a6b4d2

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

gems/smithy-client/lib/smithy-client/waiters/poller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def matches_success?(path_matcher, output, error)
7070
def matches_errorType?(path_matcher, output, error) # rubocop:disable Naming/MethodName
7171
return false unless output.nil?
7272

73-
err = path_matcher.split('#').last.split('#').first
74-
error.class.to_s.include?(err)
73+
error.class.to_s.include?(path_matcher)
7574
end
7675

7776
def equal?(actual, expected, comparator)

gems/smithy-client/spec/smithy-client/waiters_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,34 @@ module Waiters
400400
}
401401
}
402402
]
403+
},
404+
'AbsoluteErrorTypeMatcher' => {
405+
'acceptors' => [
406+
{
407+
'state' => 'success',
408+
'matcher' => {
409+
'errorType' => 'smithy.ruby.tests#MyError'
410+
}
411+
}
412+
]
403413
}
404414
}
405415
end
406416

407-
it 'succeeds when error matches' do
417+
it 'succeeds when error matches for relative shape name' do
408418
expect(client).to receive(:get_widget).and_raise(my_error)
409419
expect do
410420
client.wait_until(:error_type_matcher, input, max_wait_time: 60)
411421
end.to_not raise_error
412422
end
413423

424+
it 'succeeds when error matches for absolute shape id' do
425+
expect(client).to receive(:get_widget).and_raise(my_error)
426+
expect do
427+
client.wait_until(:absolute_error_type_matcher, input, max_wait_time: 60)
428+
end.to_not raise_error
429+
end
430+
414431
it 'retries and succeeds when matched' do
415432
output = {}
416433
2.times do

gems/smithy/lib/smithy/views/client/waiters.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ def initialize(operation, name, waiter)
5151
attr_reader :operation_name, :name, :documentation, :acceptors, :min_delay, :max_delay, :deprecated
5252

5353
def formatted_acceptors(acceptors)
54-
acceptors.each do |acceptor|
55-
if (matcher = acceptor['matcher']['output'] || acceptor['matcher']['inputOutput'])
56-
matcher['path'] = Util::Underscore.underscore_jmespath(matcher['path'])
57-
end
58-
end
54+
acceptors.each { |acceptor| preprocess_acceptor(acceptor) }
5955

6056
Util::HashFormatter.new(
6157
wrap: false,
@@ -64,6 +60,14 @@ def formatted_acceptors(acceptors)
6460
indent: ' '
6561
).format(acceptors: acceptors)
6662
end
63+
64+
def preprocess_acceptor(acceptor)
65+
if (matcher = acceptor['matcher']['output'] || acceptor['matcher']['inputOutput'])
66+
matcher['path'] = Util::Underscore.underscore_jmespath(matcher['path'])
67+
elsif (error_type = acceptor['matcher']['errorType'])
68+
acceptor['matcher']['errorType'] = error_type.split('#').last.split('#').first
69+
end
70+
end
6771
end
6872
end
6973
end

0 commit comments

Comments
 (0)