Skip to content

Commit

Permalink
Don't panic on nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Oct 6, 2023
1 parent 097f543 commit 24fd1bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/handlers/custom_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func validateCustomMetricsData(data ApplicationMetricsData) error {

for key, val := range data {
valType := reflect.TypeOf(val)
if valType == nil {
return errors.Errorf("%s value is nil, only scalar values are allowed", key)
}

switch valType.Kind() {
case reflect.Slice:
return errors.Errorf("%s value is an array, only scalar values are allowed", key)
Expand Down
8 changes: 8 additions & 0 deletions pkg/handlers/custom_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func Test_validateCustomMetricsData(t *testing.T) {
},
wantErr: true,
},
{
name: "nil value",
data: ApplicationMetricsData{
"key1": nil,
"key2": 4,
},
wantErr: true,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 24fd1bd

Please sign in to comment.