Skip to content

Commit

Permalink
config: Return error from optFns in LoadDefaultConfig (#1562)
Browse files Browse the repository at this point in the history
Adds handling of return error in LoadDefaultConfig when processing functional options for LoadOptions.
  • Loading branch information
pingleig authored Jan 24, 2022
1 parent 6625113 commit 484478f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changelog/450d4ca924cb43e1aaa66310a96b90d1.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"fmt"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -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")
}
}

0 comments on commit 484478f

Please sign in to comment.