Skip to content

Commit fa1e9c4

Browse files
improve error handling
1 parent 696e3cf commit fa1e9c4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

aws/aws_param_store.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,17 @@ func LoadConfigFromParameterStore(session *session.Session, paramPrefix string,
7272
}
7373

7474
func writeParamToConfig(config interface{}, name string, value string) global.Error {
75-
destination := reflect.ValueOf(config).Elem()
75+
destination := reflect.ValueOf(config)
76+
77+
if destination.Kind() == reflect.Ptr {
78+
return global.NewError("config must be a pointer to a structure")
79+
}
80+
81+
destination = destination.Elem()
82+
83+
if destination.Kind() == reflect.Struct {
84+
return global.NewError("config must be a pointer to a structure")
85+
}
7686

7787
// find nested field in config struct
7888
pathParts := strings.Split(name, paramStoreSeparator)

error.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func (g globalError) Warning() bool {
2121
}
2222

2323
func NewWarning(msg string, arguments ...interface{}) Error {
24-
return globalError{fmt.Sprintf(msg, arguments...), true}
24+
return &globalError{fmt.Sprintf(msg, arguments...), true}
2525
}
2626

2727
func NewError(msg string, arguments ...interface{}) Error {
28-
return globalError{fmt.Sprintf(msg, arguments...), false}
28+
return &globalError{fmt.Sprintf(msg, arguments...), false}
2929
}

0 commit comments

Comments
 (0)