-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Safer behaviour of (mis)logging badly coded marshallers #1505
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
base: master
Are you sure you want to change the base?
Conversation
ArrayMarshalerType, ObjectMarshalerType, InlineMarshalerType all call user provided methods on user provided values. They may fail/panic and have to be guarded. Use guard similar to the one for stringer with the following caveats: - ObjectMarshalerType in case of nil-ness will be logged as string rather than map. - ArrayMarshalerType - we have to insert a synthetic empty marshaller to log an empty slice. Otherwise the default shape of map shines through - InlineMarshalerType - in case of any error it will be de-inlined to show exact cause of error. Otherwise error will be attached to the wrapping object which will make debugging and fixing harder While we introduce enough coverage, the test harness is not using currently subtests. This patch does not address this to keep changes to a minimum and give time to discuss if this is necessary. Thus there are 3 tests that were changed - the error cases, the success cases and inline case (separate).
|
@JacobOaks, @tchung1118: as discussed on #1501, I am proposing a fix for #1504. |
|
@prashantv Have a look at the implementation I propose for fixing problems you outlined here: #1501 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add benchmarks to compare performances of before and after this change?
(on behalf of @sywhang from group code review)
| enc.AddString(key, "<nil>") | ||
| return | ||
| } | ||
| _ = enc.AddArray(key, emptyArrayMarshaler{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding this?
| if v := reflect.ValueOf(objectMarshaller); v.Kind() == reflect.Ptr && v.IsNil() { | ||
| enc.AddString(key, "<nil>") | ||
| return | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem necessary to log nil here separately because the error returned from here will already indicate there's a nil panic without this. Let's not do this because reflection is expensive.
ArrayMarshalerType, ObjectMarshalerType, InlineMarshalerType all call
user provided methods on user provided values.
They may fail/panic and have to be guarded.
Use guard similar to the one for stringer with the following caveats:
Otherwise the default shape of map shines through
Otherwise error will be attached to the wrapping object which will make debugging and fixing harder
While we introduce enough coverage, the test harness is not using currently subtests.
This patch does not address this to keep changes to a minimum and give time to discuss if this is necessary.
Thus there are 3 tests that were changed - the error cases, the success cases and inline case (separate).