Skip to content

Commit 346ae1c

Browse files
committed
internal/proto: set filename in FileDescriptorProto when missing
Some old descriptors don't include a filename. When missing, set it from the filename provided to proto.RegisterFile. Fixes a number of warnings in the google.golang.org/protobuf tests stemming from the legacy generated files: WARNING: proto: file "" is already registered A future release of proto will panic on registration conflicts. Change-Id: I4f7c9e4a9ecb4d2a71073b0a373ec0c800e2ec66 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/184078 Reviewed-by: Joe Tsai <[email protected]>
1 parent 1ee46df commit 346ae1c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/proto/registry.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func RegisterFile(s filePath, d fileDescGZIP) {
5252
if err := protoV2.Unmarshal(b, &pb); err != nil {
5353
panic(fmt.Sprintf("proto: unmarshal failure: %v", err))
5454
}
55+
// Some old descriptors don't include the filename.
56+
if pb.Name == nil {
57+
pb.Name = &s
58+
}
5559

5660
// Convert the raw descriptor to a structured file descriptor.
5761
fd, err := protodesc.NewFile(&pb, nil)

0 commit comments

Comments
 (0)