go
data_error
ai_generated
true
proto: unable to resolve "type.googleapis.com/pb.Payment"
ID: go/proto-any-unmarshal-type-not-found
80%Fix Rate
86%Confidence
0Evidence
2024-12-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| google.golang.org/protobuf v1.30+ | active | — | — | — |
Root Cause
protojson or proto.Unmarshal encountered an Any message whose embedded type URL is not registered in the global type registry.
generic中文
protojson 或 proto.Unmarshal 遇到 Any 消息,其内嵌 type URL 未在全局类型注册表中注册。
Workarounds
-
93% success
import _ "example.com/project/pb" // triggers init() registration // or explicit: protoregistry.GlobalTypes.RegisterMessage(paymentpb.Payment{}.ProtoReflect().Type()) -
88% success
opts := protojson.UnmarshalOptions{ Resolver: protoregistry.GlobalTypes, } if err := opts.Unmarshal(data, msg); err != nil { return err }
Dead Ends
Common approaches that don't work:
-
95% fail
Any.Value contains a serialized message with a type prefix; direct assignment yields garbage.
-
60% fail
Works only if the caller knows the type; defeats the purpose of Any and breaks polymorphic dispatch.