-
Notifications
You must be signed in to change notification settings - Fork 1.6k
proto: ability to distinguish truly invalid proto.Message values? #1013
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
Comments
\cc @neild |
For |
😕 hm… defining special magic values for these otherwise–invalid values means that they would become part of the public API, and once anyone ends up relying on that behavior, if there is any attempt to change the semantics, then we would break those that depends upon the semantics we set now. I’m all for setting it to be documented undefined behavior, or otherwise stating that it’s otherwise invalid, and that it returns a non–useful value, then we have much more leeway to change it to a useful secondary–semantic like |
Removing
|
Should there be a way for protobuf reflection to distinguish
proto.Message
values that are truly invalid?Currently, we have
protoreflect.Message.IsValid
which indicates that the current Go value is functionally a read-only empty message. This implies that the current value has protobuf type information (i.e.,Descriptor
andType
methods are callable).However, there are a number of Go types that possess a higher level of "invalid"-ness. For example, the zero value of
dynamicpb.Message
andptypes.DynamicAny
obviously cannot contain protobuf type information since they are both concrete Go types that may may represent any arbitrary protobuf message type.The issue today is that a user of protobuf reflection cannot distinguish such messages and risk panicking whenever they call the methods on
protoreflect.Message
. For example,protocmp.Transform
will choke on the zero value ofdynamicpb.Message
.Some possibilities (some or all of these may be done) regarding truly invalid values:
proto.Message.ProtoReflect
on returnsnil
.protoreflect.Message.Type
orprotoreflect.Message.Descriptor
returnsnil
.(I define "truly invalid" as a concrete value that has no sensible protobuf message type associated with it at the present moment.)
The text was updated successfully, but these errors were encountered: