{"record":{"id":"630d92e59aab5666","repo":"grpc-ecosystem/grpc-gateway","slug":"failed-to-parse-grpc-api-configuration-from-yaml-i-630d92","errorCode":null,"errorMessage":"failed to parse gRPC API Configuration from YAML in %q: %w","messagePattern":"failed to parse gRPC API Configuration from YAML in %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/descriptor/openapi_configuration.go","lineNumber":16,"sourceCode":"package descriptor\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/openapiconfig\"\n\t\"go.yaml.in/yaml/v3\"\n\t\"google.golang.org/protobuf/encoding/protojson\"\n)\n\nfunc loadOpenAPIConfigFromYAML(yamlFileContents []byte, yamlSourceLogName string) (*openapiconfig.OpenAPIConfig, error) {\n\tvar yamlContents interface{}\n\tif err := yaml.Unmarshal(yamlFileContents, &yamlContents); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse gRPC API Configuration from YAML in %q: %w\", yamlSourceLogName, err)\n\t}\n\n\tjsonContents, err := json.Marshal(yamlContents)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Reject unknown fields because OpenAPIConfig is only used here\n\tunmarshaler := protojson.UnmarshalOptions{\n\t\tDiscardUnknown: false,\n\t}\n\n\topenapiConfiguration := openapiconfig.OpenAPIConfig{}\n\tif err := unmarshaler.Unmarshal(jsonContents, &openapiConfiguration); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse OpenAPI Configuration from YAML in %q: %w\", yamlSourceLogName, err)\n\t}\n\n\treturn &openapiConfiguration, nil","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/internal/descriptor/openapi_configuration.go#L1-L34","documentation":"loadOpenAPIConfigFromYAML fails when yaml.Unmarshal cannot parse the OpenAPI/gRPC API configuration file as valid YAML. The error is raised before any protojson decoding, and wraps the yaml library's parse error (line/column info included).","triggerScenarios":"Calling LoadOpenAPIConfigFromYAML (public entry) with file contents containing YAML syntax errors: bad indentation, tabs for indentation, unbalanced quotes/brackets, or invalid YAML constructs.","commonSituations":"Hand-edited YAML config with a stray tab or missing space after a colon; heredoc-generated config with broken indentation; copy-pasted config losing indentation.","solutions":["Run a YAML linter (yamllint) on the config file and fix the reported line/column","Replace tabs with spaces in the YAML file","Validate that the file parses standalone (e.g. `python -c \"import yaml,sys; yaml.safe_load(open(sys.argv[1]))\" file.yaml`)","Diff the config against a known-good example from the repo (internal/examples)"],"exampleFix":"// before (invalid: tab indentation)\ntype:\n\tgoogle.api.HttpRule\n// after\ntype: google.api.HttpRule","handlingStrategy":"validation","validationCode":"if err := yaml.Unmarshal(contents, &map[string]interface{}{}); err != nil {\n    return fmt.Errorf(\"invalid YAML in config: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := reg.LoadOpenAPIConfigFromYAML(path); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse gRPC API Configuration from YAML\") {\n        log.Fatalf(\"fix YAML syntax in %s: %v\", path, err)\n    }\n    return err\n}","preventionTips":["Run yamllint in CI on all gateway config files","Use spaces, never tabs, in YAML","Edit configs in editors with YAML syntax highlighting","Commit a passing schema/lint check alongside config changes"],"tags":["yaml","parse-error","config"],"backgroundTag":"yaml-syntax-error","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}