{"record":{"id":"c8a64ab5d07cfdba","repo":"grpc-ecosystem/grpc-gateway","slug":"no-target-service-defined-in-the-file-c8a64a","errorCode":null,"errorMessage":"no target service defined in the file","messagePattern":"no target service defined in the file","errorType":"error_code","errorClass":"errNoTargetService","httpStatus":null,"severity":"info","filePath":"protoc-gen-openapiv2/internal/genopenapi/generator.go","lineNumber":26,"sourceCode":"\t\"path/filepath\"\n\t\"reflect\"\n\t\"sort\"\n\t\"strings\"\n\n\t\"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor\"\n\tgen \"github.com/grpc-ecosystem/grpc-gateway/v2/internal/generator\"\n\topenapioptions \"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options\"\n\t\"go.yaml.in/yaml/v3\"\n\tstatuspb \"google.golang.org/genproto/googleapis/rpc/status\"\n\t\"google.golang.org/grpc/grpclog\"\n\t\"google.golang.org/protobuf/proto\"\n\t\"google.golang.org/protobuf/reflect/protodesc\"\n\t\"google.golang.org/protobuf/types/descriptorpb\"\n\t\"google.golang.org/protobuf/types/known/anypb\"\n\t\"google.golang.org/protobuf/types/pluginpb\"\n)\n\nvar errNoTargetService = errors.New(\"no target service defined in the file\")\n\ntype generator struct {\n\treg    *descriptor.Registry\n\tformat Format\n}\n\ntype wrapper struct {\n\tfileName string\n\tswagger  *openapiSwaggerObject\n}\n\ntype GeneratorOptions struct {\n\tRegistry       *descriptor.Registry\n\tRecursiveDepth int\n}\n\n// New returns a new generator which generates grpc gateway files.\nfunc New(reg *descriptor.Registry, format Format) gen.Generator {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/protoc-gen-openapiv2/internal/genopenapi/generator.go#L8-L44","documentation":"errNoTargetService is the sentinel error returned by the generators when a .proto file contains no service definitions to render. genopenapi/Generate and gengateway's generator skip such files, and callers use errors.Is(err, errNoTargetService) to log-and-continue instead of failing the whole run. It is not a fatal condition: a proto file without services simply produces no gateway/OpenAPI output.","triggerScenarios":"Running protoc-gen-grpc-gateway or protoc-gen-openapiv2 over a .proto file that declares only messages/enums/imports and no `service` block; Generate/applyTemplate/g.generate detect zero services and return this sentinel.","commonSituations":"Passing a whole directory of protos (or an include path with common/model protos) to the plugin so non-service files are processed; splitting services out of a proto that previously had one; generating against dependency-only protos.","solutions":["Restrict the plugin invocation to proto files that contain service definitions (pass only service protos as arguments).","If the file intentionally has no service, ignore the message — with grpclog V(1) enabled it is informational only and generation succeeds.","Add a `service` block to the proto if output was expected from it.","In custom code, treat this case with errors.Is(err, errNoTargetService) and skip rather than abort."],"exampleFix":"// before\nprotoc --grpc-gateway_out=. ./proto/*.proto   # includes message-only files\n// after\nprotoc --grpc-gateway_out=. ./proto/service_foo.proto ./proto/service_bar.proto","handlingStrategy":"validation","validationCode":"// shell: only pass protos that declare services to the plugins\ngrep -L '^service ' proto/*.proto   # these will trigger errNoTargetService; exclude them","typeGuard":null,"tryCatchPattern":"// Go\nif errors.Is(err, errNoTargetService) {\n    grpclog.Infof(\"%s: skipped (no services)\", file.GetName())\n    return nil\n}","preventionTips":["Pass only service-bearing protos as plugin arguments; use -I paths for dependencies.","Treat this message as informational, not a failure.","Keep message-only protos in separate packages excluded from gateway generation."],"tags":["protobuf","code-generation","grpc","sentinel-error"],"backgroundTag":"no-target-service-defined","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}