Skip to content

Commit

Permalink
chore: return error from WriteGRPCMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
sudorandom committed Nov 16, 2024
1 parent 697fec0 commit 12041a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/fauxrpc/cmd_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func (c *GenerateCmd) Run(globals *Globals) error {
if err != nil {
return err
}
grpc.WriteGRPCMessage(os.Stdout, protoBytes)
if err := grpc.WriteGRPCMessage(os.Stdout, protoBytes); err != nil {
return err
}
default:
return fmt.Errorf("unexpected format: %s", c.Format)
}
Expand Down
11 changes: 8 additions & 3 deletions private/grpc/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import (
"io"
)

func WriteGRPCMessage(w io.Writer, msg []byte) {
func WriteGRPCMessage(w io.Writer, msg []byte) error {
prefix := make([]byte, 5)
binary.BigEndian.PutUint32(prefix[1:], uint32(len(msg)))
_, _ = w.Write(prefix)
_, _ = w.Write(msg)
if _, err := w.Write(prefix); err != nil {
return err
}
if _, err := w.Write(msg); err != nil {
return err
}
return nil
}

func ReadGRPCMessage(body io.Reader, msg []byte) (int, error) {
Expand Down
2 changes: 1 addition & 1 deletion private/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func NewHandler(service protoreflect.ServiceDescriptor, db stubs.StubDatabase, v
return
}
}
grpc.WriteGRPCMessage(w, msg)
_ = grpc.WriteGRPCMessage(w, msg)
grpcWriteStatus(w, status.New(codes.OK, ""))
})
}
Expand Down

0 comments on commit 12041a1

Please sign in to comment.