Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: Return error from optFns in LoadDefaultConfig #1562

Merged
merged 2 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
}