From a6c0e1d866becd4b8bd6d4785186bc7b42114c95 Mon Sep 17 00:00:00 2001 From: Matt Muller <53055821+mullermp@users.noreply.github.com> Date: Thu, 14 Jan 2021 13:12:41 -0800 Subject: [PATCH] Fix an issue with max_attempts and validation (#2465) --- gems/aws-sdk-core/CHANGELOG.md | 2 ++ gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb | 7 ++++--- gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gems/aws-sdk-core/CHANGELOG.md b/gems/aws-sdk-core/CHANGELOG.md index d5b122f1ef4..22159408079 100644 --- a/gems/aws-sdk-core/CHANGELOG.md +++ b/gems/aws-sdk-core/CHANGELOG.md @@ -1,6 +1,8 @@ Unreleased Changes ------------------ +* Issue - Fix an issue with `max_attempts` validation raising incorrectly. + 3.111.0 (2021-01-11) ------------------ diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb index 5f264e3f4be..912a363e742 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb @@ -176,11 +176,12 @@ def self.resolve_retry_mode(cfg) end def self.resolve_max_attempts(cfg) - value = (ENV['AWS_MAX_ATTEMPTS'] && ENV['AWS_MAX_ATTEMPTS'].to_i) || + value = (ENV['AWS_MAX_ATTEMPTS']) || Aws.shared_config.max_attempts(profile: cfg.profile) || - 3 + '3' + value = value.to_i # Raise if provided value is not a positive integer - if !value.is_a?(Integer) || value <= 0 + if value <= 0 raise ArgumentError, 'Must provide a positive integer for max_attempts profile '\ 'option or for ENV[\'AWS_MAX_ATTEMPTS\']' diff --git a/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb b/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb index 2ca345fbe0a..020f9682e72 100644 --- a/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb +++ b/gems/aws-sdk-core/spec/aws/plugins/retry_errors_spec.rb @@ -48,13 +48,13 @@ module Plugins it 'can configure max_attempts with shared config' do allow_any_instance_of(Aws::SharedConfig) - .to receive(:max_attempts).and_return(5) + .to receive(:max_attempts).and_return('5') expect(client.config.max_attempts).to eq(5) end it 'can configure max_attempts using ENV with precedence over config' do allow_any_instance_of(Aws::SharedConfig) - .to receive(:max_attempts).and_return(3) + .to receive(:max_attempts).and_return('3') ENV['AWS_MAX_ATTEMPTS'] = '1' expect(client.config.max_attempts).to eq(1) end