{"record":{"id":"6e1e01d5bfe4927b","repo":"grpc-ecosystem/grpc-gateway","slug":"failed-to-register-option-in-s-w","errorCode":null,"errorMessage":"failed to register option in %s: %w","messagePattern":"failed to register option in (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/descriptor/openapi_configuration.go","lineNumber":44,"sourceCode":"\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\n}\n\nfunc registerOpenAPIOptions(registry *Registry, openAPIConfig *openapiconfig.OpenAPIConfig, yamlSourceLogName string) error {\n\tif openAPIConfig.OpenapiOptions == nil {\n\t\t// Nothing to do\n\t\treturn nil\n\t}\n\n\tif err := registry.RegisterOpenAPIOptions(openAPIConfig.OpenapiOptions); err != nil {\n\t\treturn fmt.Errorf(\"failed to register option in %s: %w\", yamlSourceLogName, err)\n\t}\n\treturn nil\n}\n\n// LoadOpenAPIConfigFromYAML loads an  OpenAPI Configuration from the given YAML file\n// and registers the OpenAPI options the given registry.\n// This must be done after loading the proto file.\nfunc (r *Registry) LoadOpenAPIConfigFromYAML(yamlFile string) error {\n\tyamlFileContents, err := os.ReadFile(yamlFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read OpenAPI Configuration description from %q: %w\", yamlFile, err)\n\t}\n\n\tconfig, err := loadOpenAPIConfigFromYAML(yamlFileContents, yamlFile)\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/grpc-ecosystem/grpc-gateway/blob/a58a4436a376a4bcc7d8f10c4d4f919a8438bba9/internal/descriptor/openapi_configuration.go#L26-L62","documentation":"registerOpenAPIOptions wraps errors from registry.RegisterOpenAPIOptions, indicating the config file parsed fine but one or more OpenAPI options could not be applied to the registry (e.g. selector does not match any service/method, or conflicting option registration). The yamlSourceLogName identifies which config file caused it.","triggerScenarios":"LoadOpenAPIConfigFromYAML with an OpenAPIOptions entry whose selector points to a service/method/message not present in the loaded protos, or an option structure that fails validation during registration.","commonSituations":"Config referencing methods renamed or removed from the proto; selector syntax wrong (missing leading package name); loading the config before loading the proto file (LoadOpenAPIConfigFromYAML must run after loading protos).","solutions":["Ensure LoadFile/LoadProto runs before LoadOpenAPIConfigFromYAML","Fix the selector strings to match actual fully-qualified service/method names in your protos","Remove stale entries for methods/services no longer defined","Read the wrapped (%w) inner error from RegisterOpenAPIOptions for the specific offending option"],"exampleFix":"// before (selector matches nothing)\nselector: \"Foo.Bar\"\n// after\nselector: \"example.hello.Greeter.SayHello\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := reg.LoadOpenAPIConfigFromYAML(path); err != nil {\n    if strings.Contains(err.Error(), \"failed to register option\") {\n        log.Fatalf(\"check selectors in %s: %v\", path, err)\n    }\n    return err\n}","preventionTips":["Always load proto files before loading the OpenAPI config","Keep selectors as fully-qualified service/method names","Regenerate or update config when protos change","Log the wrapped inner error to identify the offending option entry"],"tags":["config","options-registration","selector"],"backgroundTag":"selector-not-found","analyzedSha":"a58a4436a376a4bcc7d8f10c4d4f919a8438bba9","analyzedAt":"2026-09-02T10:28:31.537Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}