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

Guard agains null array member input causing panic #70

Merged
merged 2 commits into from
Apr 27, 2016

Conversation

aaronkavlie-wf
Copy link
Contributor

Problem

If you have nested rules that expect an array of objects, like so:

"stuff": [
    {"foo": "bar1"},
    {"foo": "bar2"}
]

a null array member will cause a panic:

"stuff": [null]

Solution

Check for nil values and throw an error.

Code Review

@alexandercampbell-wf @tylertreat-wf

@@ -341,9 +341,13 @@ func applyNestedInboundRules(
s := reflect.ValueOf(value)
nestedValues := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
val := s.Index(i).Interface()
if val == nil {
return nil, fmt.Errorf("nested value is nil")
Copy link
Contributor

@tylertreat-wf tylertreat-wf Apr 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be errors.New("nested value is nil") instead of using fmt.Errorf since you're not formatting anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, had it that way at first, forgot to change back :-)

@tylertreat-wf
Copy link
Contributor

lgtm

@tylertreat-wf
Copy link
Contributor

+1

1 similar comment
@tannermiller-wf
Copy link
Contributor

+1

@tylertreat-wf tylertreat-wf merged commit 07477d1 into Workiva:master Apr 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants