Skip to content

Commit

Permalink
move the indication of destination message type into Codec, so a cust…
Browse files Browse the repository at this point in the history
…om Codec could obscure it
  • Loading branch information
jhump committed Sep 18, 2023
1 parent 9f777aa commit e0d59e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ func (c *protoBinaryCodec) Unmarshal(data []byte, message any) error {
if !ok {
return errNotProto(message)
}
return proto.Unmarshal(data, protoMessage)
err := proto.Unmarshal(data, protoMessage)
if err != nil {
return fmt.Errorf("unmarshal into %T: %w", message, err)
}
return nil
}

func (c *protoBinaryCodec) MarshalStable(message any) ([]byte, error) {
Expand Down Expand Up @@ -174,7 +178,11 @@ func (c *protoJSONCodec) Unmarshal(binary []byte, message any) error {
// Discard unknown fields so clients and servers aren't forced to always use
// exactly the same version of the schema.
options := protojson.UnmarshalOptions{DiscardUnknown: true}
return options.Unmarshal(binary, protoMessage)
err := options.Unmarshal(binary, protoMessage)
if err != nil {
return fmt.Errorf("unmarshal into %T: %w", message, err)
}
return nil
}

func (c *protoJSONCodec) MarshalStable(message any) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion protocol_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ func (u *connectUnaryUnmarshaler) UnmarshalFunc(message any, unmarshal func([]by
data = decompressed
}
if err := unmarshal(data.Bytes(), message); err != nil {
return errorf(CodeInvalidArgument, "unmarshal into %T: %w", message, err)
return NewError(CodeInvalidArgument, err)
}
return nil
}
Expand Down

0 comments on commit e0d59e9

Please sign in to comment.