diff --git a/.changelog/450d4ca924cb43e1aaa66310a96b90d1.json b/.changelog/450d4ca924cb43e1aaa66310a96b90d1.json new file mode 100644 index 00000000000..b57e5cf33ea --- /dev/null +++ b/.changelog/450d4ca924cb43e1aaa66310a96b90d1.json @@ -0,0 +1,8 @@ +{ + "id": "450d4ca9-24cb-43e1-aaa6-6310a96b90d1", + "type": "bugfix", + "description": "Fixes LoadDefaultConfig handling of errors returned by passed in functional options. Previously errors returned from the LoadOptions passed into LoadDefaultConfig were incorrectly ignored. [#1562](https://github.com/aws/aws-sdk-go-v2/pull/1562). Thanks to [Pinglei Guo](https://github.com/pingleig) for submitting this PR.", + "modules": [ + "config" + ] +} \ No newline at end of file diff --git a/config/config.go b/config/config.go index 80d6e83a4d3..44b88db608a 100644 --- a/config/config.go +++ b/config/config.go @@ -181,7 +181,9 @@ func (cs configs) ResolveConfig(f func(configs []interface{}) error) error { func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error) (cfg aws.Config, err error) { var options LoadOptions for _, optFn := range optFns { - optFn(&options) + if err := optFn(&options); err != nil { + return aws.Config{}, err + } } // assign Load Options to configs diff --git a/config/config_test.go b/config/config_test.go index ea65b58c999..0638fb96779 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2,6 +2,7 @@ package config import ( "context" + "fmt" "testing" "github.com/aws/aws-sdk-go-v2/aws" @@ -135,3 +136,13 @@ func TestConfigs_ResolveAWSConfig(t *testing.T) { t.Errorf("expect config sources match, got diff: \n %s", diff) } } + +func TestLoadDefaultConfig(t *testing.T) { + optWithErr := func(_ *LoadOptions) error { + return fmt.Errorf("some error") + } + _, err := LoadDefaultConfig(context.TODO(), optWithErr) + if err == nil { + t.Fatal("expect error when optFn returns error, got nil") + } +}