Graylog2 / go-gelf

GELF library for Go
http://godoc.org/github.com/Graylog2/go-gelf/gelf
MIT License
103 stars 64 forks source link

Prevent panic when unmarshalling JSON #20

Closed xose closed 6 years ago

xose commented 6 years ago

Sending a GELF message with the wrong type for any of the common fields will result in a panic.

This PR adds type assertion so any fields received with the wrong type will just be ignored.

CLAassistant commented 6 years ago

CLA assistant check
All committers have signed the CLA.

mariussturm commented 6 years ago

Thanks for the contribution! Could you add one or two tests for this scenario?

xose commented 6 years ago

Yes, I'll write some tests. But I've been thinking that simply ignoring the field when it has the wrong type may not be the best overall solution. It works for my use case but returning an error could be a better approach for the library.

Thoughts? Should I rewrite the PR to return an error instead?

mariussturm commented 6 years ago

@xose yeah you are right, we return an error anyways when the unmarshalling fails so we could also inform the caller that a type mismatch is happening. So a return err would be great.