{"record":{"id":"1de96bf3f9abf1e9","repo":"grpc/grpc-go","slug":"error-parsing-config-for-policy-q-v","errorCode":null,"errorMessage":"error parsing config for policy %q: %v","messagePattern":"error parsing config for policy %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/balancer/gracefulswitch/config.go","lineNumber":78,"sourceCode":"\t\tvar jsonCfg json.RawMessage\n\t\tfor name, jsonCfg = range e {\n\t\t}\n\n\t\tbuilder := balancer.Get(name)\n\t\tif builder == nil {\n\t\t\t// Skip unregistered balancer names.\n\t\t\tcontinue\n\t\t}\n\n\t\tparser, ok := builder.(balancer.ConfigParser)\n\t\tif !ok {\n\t\t\t// This is a valid child with no config.\n\t\t\treturn &lbConfig{childBuilder: builder}, nil\n\t\t}\n\n\t\tcfg, err := parser.ParseConfig(jsonCfg)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing config for policy %q: %v\", name, err)\n\t\t}\n\t\treturn &lbConfig{childBuilder: builder, childConfig: cfg}, nil\n\t}\n\n\treturn nil, fmt.Errorf(\"no supported policies found in config: %v\", string(cfg))\n}\n","sourceCodeStart":60,"sourceCodeEnd":85,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/balancer/gracefulswitch/config.go#L60-L85","documentation":"Returned by gracefulswitch.ParseConfig when the child balancer's ConfigParser.ParseConfig rejects the config JSON. The gracefulswitch parser found a registered builder for the policy name (config.go:64-68) and confirmed it implements balancer.ConfigParser (config.go:70-74), but the builder's own parser returned an error. The %q is the policy name; %v is the underlying parse error from the child.","triggerScenarios":"Passing a loadBalancingConfig entry whose inner config JSON is invalid for the named policy. For example, a weighted_round_robin config with invalid child field types, or a priority config referencing unknown child policies. The error surfaces through gracefulswitch.ParseConfig -> parser.ParseConfig at config.go:76-78.","commonSituations":"Version mismatch between the service config JSON schema and the installed gRPC version. A config generated for a newer balancer that expects different field names or types. Typos in config field names that the child parser strictly validates.","solutions":["Inspect the wrapped error (%v) to identify which field or value the child parser rejected","Compare your config JSON against the child balancer's expected config struct definition for your gRPC version","Ensure the gRPC version that generated the service config matches the version running in the client","Test the child config in isolation by calling the specific balancer's ParseConfig directly"],"exampleFix":"// before: weighted_round_robin with invalid child config\n{\"loadBalancingConfig\": [{\"weighted_round_robin\": {\"children\": {\"child-0\": {\"weight\": \"not-a-number\"}}}}]}\n\n// after: correct numeric weight\n{\"loadBalancingConfig\": [{\"weighted_round_robin\": {\"children\": {\"child-0\": {\"weight\": 1}}}}]}","handlingStrategy":"validation","validationCode":"// Validate child config by testing the specific balancer's parser in isolation\nfunc validateChildConfig(policyName string, childCfg json.RawMessage) error {\n    builder := balancer.Get(policyName)\n    if builder == nil {\n        return fmt.Errorf(\"balancer %q not registered\", policyName)\n    }\n    parser, ok := builder.(balancer.ConfigParser)\n    if !ok {\n        return nil // no config to validate\n    }\n    _, err := parser.ParseConfig(childCfg)\n    return err\n}","typeGuard":null,"tryCatchPattern":"// When calling ParseConfig, inspect the wrapped error for child-specific details\ncfg, err := gracefulswitch.ParseConfig(rawCfg)\nif err != nil {\n    // Check if this is a child parse error (contains 'error parsing config for policy')\n    if strings.Contains(err.Error(), \"error parsing config for policy\") {\n        // Extract the policy name and underlying cause for targeted fix\n        log.Printf(\"child balancer config invalid: %v\", err)\n    }\n    return err\n}","preventionTips":["Pin your gRPC version so the service config schema matches the running code","Test child balancer configs in isolation using the specific balancer's ParseConfig","Use integration tests that exercise the full service config parsing path"],"tags":["grpc","balancer","config","gracefulswitch"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}