golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.64k stars 1.58k forks source link

reflection/protodesc: placeholder files produce a descriptor with strange syntax value #1575

Closed jhump closed 7 months ago

jhump commented 7 months ago

When using protodesc.ToFileDescriptor to convert a file and its transitive dependencies to a *descriptorpb.FileDescriptorSet, if any of the files are placeholders (due to an imported file being absent from the registry, typically due to importing it using the wrong path), the result is a *descriptor.FileDescriptorProto message whose Syntax field is set to the string "<unknown:0>". While the resulting descriptor won't be usable (since it will be empty and thus not contain any of the symbols that the importing file expects), it seems like a link failure would be less surprising/more intuitive than proto: invalid syntax: "<unknown:0>".

So I think this logic should just skip setting the Syntax field (i.e. leave it nil since it's a proto2 optional field) if the source protoreflect.FileDescriptor returns a syntax value where syntax.IsValid() is false.