Skip to content

Update desc/sourceinfo to not wrap descriptors#622

Merged
jhump merged 4 commits intomainfrom
jh/update-sourceinfo-to-not-wrap-descriptors
Sep 4, 2024
Merged

Update desc/sourceinfo to not wrap descriptors#622
jhump merged 4 commits intomainfrom
jh/update-sourceinfo-to-not-wrap-descriptors

Conversation

@jhump
Copy link
Copy Markdown
Owner

@jhump jhump commented Sep 2, 2024

The desc/sourceinfo package previously wrapped descriptors, by returning an implementation of the various protoreflect.Descriptor interfaces that embedded the original descriptor values. However, these various interfaces are all defined as "do not implement". So, to avoid future issues where the protobuf runtime may type-assert implementations to their own internal types (which would panic/fail with the concrete wrapper types in this package), we no longer wrap this way.

This also happens to resolve #618 (since there's no more wrapping, an incorrect typed-nil wrapper can't escape).

Comment thread desc/imports.go
Comment on lines -37 to -40
//
// Deprecated: the new protobuf runtime (v1.4+) verifies that import paths are
// correct and that descriptors can be linked during package initialization. So
// registering alternate paths is no longer useful or necessary.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also un-deprecated these while in here. I was mistaken when I wrote this comment: the protobuf runtime does not verify that import paths are correct. Instead it will happily delay the errors until you need to use reflection. At reflection time, it can provide "placeholder" descriptors for files that are imported using the wrong name. So all of the work-arounds in this file for patching import paths are, in fact, still useful.

Comment thread desc/load.go
func LoadFileDescriptor(file string) (*FileDescriptor, error) {
d, err := sourceinfo.GlobalFiles.FindFileByPath(file)
if err == protoregistry.NotFound {
if errors.Is(err, protoregistry.NotFound) {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other low-hanging fruit clean-up while in here.

…re better named and allow returning an error
@jhump jhump merged commit 06e5c08 into main Sep 4, 2024
@jhump jhump deleted the jh/update-sourceinfo-to-not-wrap-descriptors branch September 4, 2024 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE from sourceinfo wrapping logic

1 participant