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

Error compiling generated code with third party imports #6

Closed
gmather opened this issue Jun 10, 2021 · 4 comments · Fixed by #7
Closed

Error compiling generated code with third party imports #6

gmather opened this issue Jun 10, 2021 · 4 comments · Fixed by #7

Comments

@gmather
Copy link

gmather commented Jun 10, 2021

Hello,

I was looking to experiment with this and ran into the following error:

type *"google.golang.org/genproto/googleapis/rpc/status".Status has no field or method MarshalToSizedBufferVT

The protobuf files that are complaining import files like:

import "google/rpc/status.proto";

with messages that look like:

message TestMessage {
   google.rpc.Status status = 2;
}

The google/rpc/status.proto file is copied locally for the code generation, but the generated code is importing the Go module from google.golang.org/genproto/googleapis/rpc/status so it's not part of the vtproto generation steps.

Is this an issue that you've had to resolve or any suggestions on how to approach this?

@vmg
Copy link
Member

vmg commented Jun 10, 2021

Hiii @gmather! This is indeed a real issue. Right now the check for foreign imports is really naive:

foreign := strings.HasPrefix(string(message.Desc.FullName()), "google.protobuf.")

I need to come up with a better way to perform this check. Let me think it through.

@elvizlai
Copy link

The related issue:
x.proto

syntax = "proto3";

package api.common;

option go_package          = "api/common";

import public "google/api/field_behavior.proto";
import public "google/api/httpbody.proto";
import public "google/protobuf/any.proto";
import public "google/protobuf/empty.proto";
import public "google/protobuf/field_mask.proto";
import public "google/protobuf/struct.proto";
import public "google/protobuf/timestamp.proto";
import public "google/protobuf/wrappers.proto";

message X {
}

The generated code has error: v.SizeVT undefined (type *structpb.Value has no field or method SizeVT)

@alexism
Copy link

alexism commented Jun 14, 2021

@vmg
I ran into that issue as well.
For the "foreign" test, instead of relying on the message full name, could we instead test the interfaces implemented by the messages? Similarly to what the gRPC codec does.

The test would be performed before invoking any *VT functions.

For example, for the "unmarshal" feature, the generated code could be something like:

			if o, ok := interface{}(m.MY_FIELD).(interface{
				UnmarshalVT([]byte) error
			});ok{
				if err := o.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil {
					return err
				}
			}else{
				if err := proto.Unmarshal(dAtA[iNdEx:postIndex], m.MY_FIELD); err!=nil{
					return err
				}
			}

@vmg
Copy link
Member

vmg commented Jun 15, 2021

I like that suggestion! I've implemented it in #7 -- can you guys give this a go and see if it works in your codebases?

@vmg vmg closed this as completed in #7 Jun 16, 2021
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 a pull request may close this issue.

4 participants