{"record":{"id":"0e5141adb6b66b24","repo":"grpc-ecosystem/grpc-gateway","slug":"failed-to-read-code-generator-request-w","errorCode":null,"errorMessage":"failed to read code generator request: %w","messagePattern":"failed to read code generator request: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/codegenerator/parse_req.go","lineNumber":15,"sourceCode":"package codegenerator\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\n\t\"google.golang.org/protobuf/proto\"\n\t\"google.golang.org/protobuf/types/pluginpb\"\n)\n\n// ParseRequest parses a code generator request from a proto Message.\nfunc ParseRequest(r io.Reader) (*pluginpb.CodeGeneratorRequest, error) {\n\tinput, err := io.ReadAll(r)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read code generator request: %w\", err)\n\t}\n\treq := new(pluginpb.CodeGeneratorRequest)\n\tif err := proto.Unmarshal(input, req); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal code generator request: %w\", err)\n\t}\n\treturn req, nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/internal/codegenerator/parse_req.go#L1-L23","documentation":"ParseRequest wraps any io.ReadAll failure when reading a protoc plugin CodeGeneratorRequest from stdin (or another reader). Protoc plugins receive their request as serialized protobuf on stdin; if the stream cannot be read, the plugin cannot proceed.","triggerScenarios":"Running a plugin binary (protoc-gen-*) whose main calls codegenerator.ParseRequest(os.Stdin) when stdin is a closed pipe, a broken pipe occurs, or the reader errors mid-read.","commonSituations":"Invoking the plugin binary directly in a terminal with no stdin redirection; protoc killed mid-invocation leaving a broken pipe; CI sandboxes that deny stdin access; shell pipelines where the producer failed.","solutions":["Run the binary only via protoc (protoc --plugin=... --grpc-gateway_out=... ) so a valid serialized request is piped to stdin","When testing manually, pipe a captured request file: protoc-gen-x < request.bin","Check disk/pipe environment (ulimit, container stdin settings) if protoc itself reports the failure"],"exampleFix":"// before\n./protoc-gen-myplugin   # no stdin -> read error\n// after\nprotoc --plugin=protoc-gen-myplugin=./protoc-gen-myplugin --myplugin_out=. api.proto","handlingStrategy":"try-catch","validationCode":"// Ensure stdin is provided when invoking manually:\n//   stat, _ := os.Stdin.Stat()\n//   if (stat.Mode() & os.ModeCharDevice) != 0 {\n//       fmt.Fprintln(os.Stderr, \"expect piped CodeGeneratorRequest on stdin\")\n//       os.Exit(1)\n//   }","typeGuard":null,"tryCatchPattern":"req, err := codegenerator.ParseRequest(os.Stdin)\nif err != nil {\n    // message begins with \"failed to read code generator request:\"\n    grpclog.Fatalf(\"plugin input error: %v\", err)\n}","preventionTips":["Always invoke plugin binaries through protoc, never interactively","Test plugins with a captured request: protoc ... --grpc-gateway_out and replay the serialized file","Check that CI containers don't close stdin for protoc runs"],"tags":["go","protoc","plugin","io"],"backgroundTag":"plugin-stdin-read-failed","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}