rogchap / wombat

Cross platform gRPC client
MIT License
1.4k stars 52 forks source link

Register googleapis error details message types #33

Closed optiman closed 3 years ago

optiman commented 3 years ago

Richer error model All errdetails types are registered in init() of google.golang.org/genproto/googleapis/rpc/errdetails package. Just needed to import it.

Before: before

After: details

optiman commented 3 years ago

To clarify how this works:

On import of google.golang.org/genproto/googleapis/rpc/errdetails package func init() { file_google_rpc_error_details_proto_init() } is executed, which runs method Build() on protoimpl.TypeBuilder that registers all message types from this package in protoregistry.GlobalTypes.

Then, before emitting eventInPayloadReceived formatPayload() is executed, where prototext.MarshalOptions is using protoregistry.GlobalTypes as a type resolver by default to automatically marshal google.protobuf.Any fields if its TypeUrl was registered beforehand in the resolver.

rogchap commented 3 years ago

Thanks @optiman. Looks good. Do you mind updating the CHANGELOG.md file in the "Unreleased" section? Don't forget to add your name to get the credit 😄

optiman commented 3 years ago

Ok, done.