-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add type safe Value definition for OTTL #45410
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: main
Are you sure you want to change the base?
Conversation
| return newValue(false, true) | ||
| } | ||
|
|
||
| func ToBoolValue(v Value) (BoolValue, error) { |
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.
Question: Do we want to support automatic type conversion when possible, or ask users to explicitly call a conversion function like "String(attributes["foo"])"
f602950 to
db552bc
Compare
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.
Maybe just a personal preference:
Instead of implementing NewXValue and NewNilXValue for every type, just have NewXValue and figure out the nil internally before calling newValue().
|
|
||
| func (v value[V]) Val() V { | ||
| if v.isNil { | ||
| panic("null pointer exception") |
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.
Do we really want to do a full crash here? Also, I feel we should, at least, provide some information about why this happened or something.
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.
What else should be the behavior? Similar to when you de-reference a pointer, I am not sure what can I do, because if I return a "zero-initialized" value will corrupt/produce wrong results.
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.
How about returning an error and drop, somehow, that data?
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.
Sorry, why is that better? Isn't the same one check caller needs to do?
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.
Well, with panic, the collector crashes, leading to all data lost. With the error... maybe one bad record, collector keeps running.
I agree caller should to the check but there can be mistakes. We can fail from the caller but providing some extra context.
At least, something like fmt.Sprintf("ottlruntime: Val() called on nil %T value", v.v)
Signed-off-by: Bogdan Drutu <[email protected]>
db552bc to
04856bc
Compare
@florianl can you help me with a code snippet to understand what is the proposal on how do you know if the value is nil or not? |
My idea is going in the direction as discussed in #45410 (comment). The options I see are like this: But reading your comment, it sounds like that is not a preferred option due to the allocation. An alternative could look like this: |
Updates #45365
This PR adds all supported types and the concept of a "Value". A value can be a concrete type value or a nil value of that type. There is a special "NoneValue" that will be used for functions that don't return anything.
Skipping changelog since this code is not yet plugged to be used in the binary.