Generate implicit dependencies
Hello!
We are trying to implement Richer Error Model for gRPC.
We want to include such dependencies like google.rpc.Status and all messages from error_details.proto to our distributed package during the build stage.
I see that https://buf.build/googleapis/googleapis/docs/main:google.rpc has all necessary dependencies.
How can we include all needed dependencies to our descriptors and generated models with buf build and buf generate?
Thank you!
Hi @gigi - check out the Buf Schema Registry tutorial! This will walk you through adding a dependency on googleapis and using buf build and buf generate with this dependency.
Hey @smallsamantha, Thanks for quick response!
We've already added the googleapis dependencies and they work for dependencies that are explicitly imported into the .proto files.
Is there a way to include dependencies mentioned above that are part of the infrastructure layer and not part of the business protocol?
The answer for how to do that depends on the language you're using in your implementation. For example, if you're using go, we recommend using google.golang.org/genproto/googleapis/rpc/errdetails as described in our Connect error details documentation here. If you're using another language you may need to explicitly generate the types from googleapis similar to how you're generating your own definitions. So you might run buf generate buf.build/googleapis/googleapis in addition to your buf generate myprotos invocation.
Let me know if that gets you going in the right direction!
We use NestJS. It seems there is no proper error details support under the hood. We have to pack and pass metadata via trailers by hand.
Such tools like grpcui or Kreya.app don't support error_details out of the box and its convenient to pass just one descriptors file that includes all necessary protos.
buf generate buf.build/googleapis/googleapis
This approach resolves a lot of not used protos. We should remove all except two files)
We ended up with empty file with necessary imports and excluded this file from buf lint command...
syntax = "proto3";
package app.rpc.v1;
import "google/rpc/status.proto";
import "google/rpc/error_details.proto";
option csharp_namespace = "app.Rpc.V1";
option go_package = "app/rpc/v1";
option java_multiple_files = true;
option java_package = "com.app.rpc.v1";
It works for now... Maybe we will find better solution soon Thanks for your answers