diff --git a/example/set-data-on-message/main.go b/example/set-data-on-message/main.go index b1afcdf..00a5048 100644 --- a/example/set-data-on-message/main.go +++ b/example/set-data-on-message/main.go @@ -14,7 +14,9 @@ import ( func main() { { msg := &elizav1.SayResponse{} - fauxrpc.SetDataOnMessage(msg) + if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil { + log.Fatalf("err: %s", err) + } b, err := protojson.MarshalOptions{Indent: " "}.Marshal(msg) if err != nil { log.Fatalf("err: %s", err) @@ -24,7 +26,9 @@ func main() { { msg := &ownerv1.Owner{} - fauxrpc.SetDataOnMessage(msg) + if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil { + log.Fatalf("err: %s", err) + } b, err := protojson.MarshalOptions{Indent: " "}.Marshal(msg) if err != nil { log.Fatalf("err: %s", err) @@ -34,7 +38,9 @@ func main() { { msg := &runtimeapi.ListMetricDescriptorsResponse{} - fauxrpc.SetDataOnMessage(msg) + if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil { + log.Fatalf("err: %s", err) + } b, err := protojson.MarshalOptions{Indent: " "}.Marshal(msg) if err != nil { log.Fatalf("err: %s", err) diff --git a/fauxplugin/handlers.go b/fauxplugin/handlers.go index cb00cca..9fdf50c 100644 --- a/fauxplugin/handlers.go +++ b/fauxplugin/handlers.go @@ -10,7 +10,7 @@ import ( ) func UnaryHandler[T *proto.Message](ctx context.Context, opts fauxrpc.GenOptions, msg *T) (*connect.Response[T], error) { - fauxrpc.SetDataOnMessage(**msg, opts) + _ = fauxrpc.SetDataOnMessage(**msg, opts) return connect.NewResponse(msg), nil } @@ -26,7 +26,7 @@ func BidiStreamHandler[I proto.Message, O proto.Message](ctx context.Context, st }) eg.Go(func() error { var msg O - fauxrpc.SetDataOnMessage(msg, opts) + _ = fauxrpc.SetDataOnMessage(msg, opts) return stream.Send(&msg) }) return eg.Wait() diff --git a/gen_fields.go b/gen_fields.go index aca65bb..6624444 100644 --- a/gen_fields.go +++ b/gen_fields.go @@ -98,12 +98,12 @@ func getFieldValue(fd protoreflect.FieldDescriptor, opts GenOptions) *protorefle } nested := newMessage(fd.Message()) - setDataOnMessage(nested.Interface(), opts.nested()) + _ = setDataOnMessage(nested.Interface(), opts.nested()) v := protoreflect.ValueOf(nested) return &v case protoreflect.GroupKind: nested := newMessage(fd.Message()) - setDataOnMessage(nested.Interface(), opts.nested()) + _ = setDataOnMessage(nested.Interface(), opts.nested()) v := protoreflect.ValueOf(nested) return &v } diff --git a/gen_msg_test.go b/gen_msg_test.go index c2c05c5..efcaad4 100644 --- a/gen_msg_test.go +++ b/gen_msg_test.go @@ -2,6 +2,7 @@ package fauxrpc_test import ( "fmt" + "log" "testing" elizav1 "buf.build/gen/go/connectrpc/eliza/protocolbuffers/go/connectrpc/eliza/v1" @@ -19,7 +20,9 @@ var AllTypes = testv1.File_test_v1_test_proto.Messages().ByName("AllTypes") func ExampleSetDataOnMessage() { msg := &elizav1.SayResponse{} - fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}) + if err := fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}); err != nil { + log.Fatalf("error: %s", err) // handle error + } b, _ := protojson.MarshalOptions{Indent: " "}.Marshal(msg) fmt.Println(string(b)) } @@ -46,7 +49,7 @@ func TestNewMessage(t *testing.T) { t.Run("AllTypes - dynamicpb", func(t *testing.T) { md := testv1.File_test_v1_test_proto.Messages().ByName("AllTypes") msg := dynamicpb.NewMessage(md) - fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}) + require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})) assertFieldIsSet(t, md, msg, "doubleValue") assertFieldIsSet(t, md, msg, "doubleValue") assertFieldIsSet(t, md, msg, "floatValue") @@ -83,7 +86,7 @@ func TestNewMessage(t *testing.T) { t.Run("AllTypes - concrete", func(t *testing.T) { msg := &testv1.AllTypes{} - fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}) + require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})) md := msg.ProtoReflect().Descriptor() pmsg := msg.ProtoReflect() assertFieldIsSet(t, md, pmsg, "doubleValue") @@ -123,7 +126,7 @@ func TestNewMessage(t *testing.T) { t.Run("ParameterValues - dynamicpb", func(t *testing.T) { md := testv1.File_test_v1_test_proto.Messages().ByName("ParameterValues") msg := dynamicpb.NewMessage(md) - fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}) + require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})) assertFieldIsSet(t, md, msg, "doubleValue") assertFieldIsSet(t, md, msg, "floatValue") assertFieldIsSet(t, md, msg, "int32Value") @@ -156,7 +159,7 @@ func TestNewMessage(t *testing.T) { t.Run("ParameterValues - concrete", func(t *testing.T) { msg := &testv1.ParameterValues{} - fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{}) + require.NoError(t, fauxrpc.SetDataOnMessage(msg, fauxrpc.GenOptions{})) md := msg.ProtoReflect().Descriptor() pmsg := msg.ProtoReflect() assertFieldIsSet(t, md, pmsg, "doubleValue")