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

fix panic, when service Handler returns (nil, nil) #7227

Closed
wants to merge 2 commits into from

Conversation

holdno
Copy link
Contributor

@holdno holdno commented May 11, 2024

Fix panic, when service Handler returns (nil, nil)

Why wasn't this done before? Is it because it introduced reflection?

@dfawley
Copy link
Member

dfawley commented May 13, 2024

Why wasn't this done before? Is it because it introduced reflection?

Probably. I don't think it's a good idea to bring in reflection. Isn't this a programming error if it happens, anyway?

@dfawley dfawley closed this May 13, 2024
@holdno
Copy link
Contributor Author

holdno commented May 14, 2024

Why wasn't this done before? Is it because it introduced reflection?

Probably. I don't think it's a good idea to bring in reflection. Isn't this a programming error if it happens, anyway?

or fix it in go-gen handler.

handler := func(ctx context.Context, req interface{}) (interface{}, error) {
    reply, err := srv.(MetricsServiceServer).GetGauge(ctx,  req.(*GaugeRequest))
    if reply == nil {
        return nil, err
    }
    return reply, err
}

I believe that regardless of whether it's the developer's fault that leads to two nil return values, the framework should not continue to pass down a 'nil' that cannot be confirmed as nil. This leads to multiple implementations having to defend against this issue downstream, and developers being unable to anticipate the error messages they might receive.

Alternatively, this could be a bug in the implementation of protobuf serialization.

proto.Marshal(vv)
// Marshal impl:
func Marshal(m Message) ([]byte, error) {
	if m == nil { // not matched
		return nil, nil
	}

	out, err := MarshalOptions{}.marshal(nil, m.ProtoReflect())
	if len(out.Buf) == 0 && err == nil {
		out.Buf = emptyBytesForMessage(m)
	}
	return out.Buf, err
}

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.

None yet

3 participants