From ca7d23f1226281f769146255ea81fc69e61f7568 Mon Sep 17 00:00:00 2001 From: matst80 Date: Wed, 3 Dec 2025 10:22:41 +0100 Subject: [PATCH] crash if not correct type --- pkg/actor/mutation_registry.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/actor/mutation_registry.go b/pkg/actor/mutation_registry.go index 6134f8a..7a059a4 100644 --- a/pkg/actor/mutation_registry.go +++ b/pkg/actor/mutation_registry.go @@ -104,12 +104,17 @@ func NewMutation[V any, T proto.Message](handler func(*V, T) error) *RegisteredM // This avoids relying on reflect.TypeFor (which can yield unexpected results in some toolchains) // and ensures we always peel off the pointer layer for proto messages. create := func() proto.Message { - m := new(T) - return *m + var t T + rt := reflect.TypeOf(t) + if rt != nil && rt.Kind() == reflect.Pointer { + return reflect.New(rt.Elem()).Interface().(proto.Message) + } + log.Fatalf("expected to create proto message got %+v", rt) + return nil } instance := create() rt := reflect.TypeOf(instance) - if rt.Kind() == reflect.Ptr { + if rt.Kind() == reflect.Pointer { rt = rt.Elem() } return &RegisteredMutation[V, T]{ @@ -222,7 +227,7 @@ func (r *ProtoMutationRegistry) Apply(ctx context.Context, grain any, msg ...pro } // Typed nil: interface holds concrete proto message type whose pointer value is nil. rv := reflect.ValueOf(m) - if rv.Kind() == reflect.Ptr && rv.IsNil() { + if rv.Kind() == reflect.Pointer && rv.IsNil() { continue } rt := indirectType(reflect.TypeOf(m))