rpc: dataconn: handle incorrect handler return values

refs #137
This commit is contained in:
Christian Schwarz 2019-03-16 14:46:53 +01:00
parent 4ee00091d6
commit b2c5ffcaea

View File

@ -146,12 +146,17 @@ func (s *Server) serveConn(nc *transport.AuthConn) {
// if marshaling fails. We consider failed marshaling a handler error // if marshaling fails. We consider failed marshaling a handler error
var protobuf *bytes.Buffer var protobuf *bytes.Buffer
if handlerErr == nil { if handlerErr == nil {
protobufBytes, err := proto.Marshal(res) if res == nil {
if err != nil { handlerErr = fmt.Errorf("implementation error: handler for endpoint %q returns nil error and nil result", endpoint)
s.log.WithError(err).Error("cannot marshal handler protobuf") s.log.WithError(err).Error("handle implementation error")
handlerErr = err } else {
protobufBytes, err := proto.Marshal(res)
if err != nil {
s.log.WithError(err).Error("cannot marshal handler protobuf")
handlerErr = err
}
protobuf = bytes.NewBuffer(protobufBytes) // SHADOWING
} }
protobuf = bytes.NewBuffer(protobufBytes) // SHADOWING
} }
var resHeaderBuf bytes.Buffer var resHeaderBuf bytes.Buffer