Skip to content

Commit 484478f

Browse files
authored
config: Return error from optFns in LoadDefaultConfig (#1562)
Adds handling of return error in LoadDefaultConfig when processing functional options for LoadOptions.
1 parent 6625113 commit 484478f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "450d4ca9-24cb-43e1-aaa6-6310a96b90d1",
3+
"type": "bugfix",
4+
"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.",
5+
"modules": [
6+
"config"
7+
]
8+
}

config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ func (cs configs) ResolveConfig(f func(configs []interface{}) error) error {
181181
func LoadDefaultConfig(ctx context.Context, optFns ...func(*LoadOptions) error) (cfg aws.Config, err error) {
182182
var options LoadOptions
183183
for _, optFn := range optFns {
184-
optFn(&options)
184+
if err := optFn(&options); err != nil {
185+
return aws.Config{}, err
186+
}
185187
}
186188

187189
// assign Load Options to configs

config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/aws/aws-sdk-go-v2/aws"
@@ -135,3 +136,13 @@ func TestConfigs_ResolveAWSConfig(t *testing.T) {
135136
t.Errorf("expect config sources match, got diff: \n %s", diff)
136137
}
137138
}
139+
140+
func TestLoadDefaultConfig(t *testing.T) {
141+
optWithErr := func(_ *LoadOptions) error {
142+
return fmt.Errorf("some error")
143+
}
144+
_, err := LoadDefaultConfig(context.TODO(), optWithErr)
145+
if err == nil {
146+
t.Fatal("expect error when optFn returns error, got nil")
147+
}
148+
}

0 commit comments

Comments
 (0)