Skip to content

Conversation

carmo-evan
Copy link
Contributor

No description provided.

Copy link
Owner

@jhump jhump left a comment

Choose a reason for hiding this comment

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

I suspect you'll find similar panics happen when resolving the request/response types of an RPC method (in *MethodDescriptor.resolve) Would you mind adding a similar fix there, too?

BTW, I suggested some tweaks to the error message. This code isn't trying to convert anything. The issue is that the descriptor is malformed: references that should be enums or messages refer to the wrong kind of element. (FWIW, protoc will never produce malformed descriptors like this, so I'm assuming you are seeing this panics when trying to create your own descriptors or using a tool that is producing invalid descriptors.)

}
enumType, ok := desc.(*EnumDescriptor)
if !ok {
return fmt.Errorf("could not convert desc %s to EnumDescriptor. TypeName: %s", desc, fd.proto.GetTypeName())
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("could not convert desc %s to EnumDescriptor. TypeName: %s", desc, fd.proto.GetTypeName())
return fmt.Errorf("field %v indicates a type of enum, but references %q which is %T", fd.fqn, fd.proto.GetTypeName(), desc)

}
msgType, ok := desc.(*MessageDescriptor)
if !ok {
return fmt.Errorf("could not convert desc %s to MessageDescriptor. TypeName: %s", desc, fd.proto.GetTypeName())
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("could not convert desc %s to MessageDescriptor. TypeName: %s", desc, fd.proto.GetTypeName())
return fmt.Errorf("field %v indicates a type of message, but references %q which is %T", fd.fqn, fd.proto.GetTypeName(), desc)

}
msgType, ok := desc.(*MessageDescriptor)
if !ok {
return fmt.Errorf("could not convert desc %s to MessageDescriptor. TypeName: %s", desc, fd.proto.GetTypeName())
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("could not convert desc %s to MessageDescriptor. TypeName: %s", desc, fd.proto.GetTypeName())
return fmt.Errorf("field %v extends %q which should be a message but is %T", fd.fqn, fd.proto.GetExtendee(), desc)

@jhump
Copy link
Owner

jhump commented Aug 18, 2022

Superceded by #525

@jhump jhump closed this Aug 18, 2022
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.

2 participants