Skip to content
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

Update desc/sourceinfo to not wrap descriptors #622

Merged
merged 4 commits into from
Sep 4, 2024

Conversation

jhump
Copy link
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 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
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.

@@ -33,7 +34,7 @@ var (
// re-processed if the same file is fetched again later.
func LoadFileDescriptor(file string) (*FileDescriptor, error) {
d, err := sourceinfo.GlobalFiles.FindFileByPath(file)
if err == protoregistry.NotFound {
if errors.Is(err, protoregistry.NotFound) {
Copy link
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
6 checks passed
@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