client/grpc: fix panic on invalid message (#1191)
* client/grpc: fix panic on invalid message * travis: disable lint and race for now Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		| @@ -6,8 +6,8 @@ env: | |||||||
| before_script: | before_script: | ||||||
|   - go install github.com/golangci/golangci-lint/cmd/golangci-lint |   - go install github.com/golangci/golangci-lint/cmd/golangci-lint | ||||||
| script: | script: | ||||||
|   - golangci-lint run || true |   #  - golangci-lint run || true | ||||||
|   - go test -v -race ./... || true |     #  - go test -v -race ./... || true | ||||||
|   - go test -v ./... |   - go test -v ./... | ||||||
| notifications: | notifications: | ||||||
|   slack: |   slack: | ||||||
|   | |||||||
| @@ -69,15 +69,21 @@ func (w wrapCodec) Unmarshal(data []byte, v interface{}) error { | |||||||
| } | } | ||||||
|  |  | ||||||
| func (protoCodec) Marshal(v interface{}) ([]byte, error) { | func (protoCodec) Marshal(v interface{}) ([]byte, error) { | ||||||
| 	b, ok := v.(*bytes.Frame) | 	switch m := v.(type) { | ||||||
| 	if ok { | 	case *bytes.Frame: | ||||||
| 		return b.Data, nil | 		return m.Data, nil | ||||||
|  | 	case proto.Message: | ||||||
|  | 		return proto.Marshal(m) | ||||||
| 	} | 	} | ||||||
| 	return proto.Marshal(v.(proto.Message)) | 	return nil, fmt.Errorf("failed to marshal: %v is not type of *bytes.Frame or proto.Message", v) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (protoCodec) Unmarshal(data []byte, v interface{}) error { | func (protoCodec) Unmarshal(data []byte, v interface{}) error { | ||||||
| 	return proto.Unmarshal(data, v.(proto.Message)) | 	m, ok := v.(proto.Message) | ||||||
|  | 	if !ok { | ||||||
|  | 		return fmt.Errorf("failed to unmarshal: %v is not type of proto.Message", v) | ||||||
|  | 	} | ||||||
|  | 	return proto.Unmarshal(data, m) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (protoCodec) Name() string { | func (protoCodec) Name() string { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user