{"record":{"id":"417ec260b4a98685","repo":"grpc/grpc-go","slug":"failed-to-marshal-built-priority-config-struct-int","errorCode":null,"errorMessage":"failed to marshal built priority config struct into json: %v","messagePattern":"failed to marshal built priority config struct into json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/xds/balancer/cdsbalancer/configbuilder.go","lineNumber":103,"sourceCode":"//\t          ┌────────┐\n//\t          │priority│\n//\t          └┬──────┬┘\n//\t           │      │\n//\t┌──────────▼─┐  ┌─▼──────────┐\n//\t│cluster_impl│  │cluster_impl│\n//\t└──────┬─────┘  └─────┬──────┘\n//\t       │              │\n//\t┌──────▼─────┐  ┌─────▼──────┐\n//\t│xDSLBPolicy │  │xDSLBPolicy │ (Locality and Endpoint picking layer)\n//\t└────────────┘  └────────────┘\nfunc buildPriorityConfigJSON(priorities []*priorityConfig, xdsLBPolicy *internalserviceconfig.BalancerConfig) ([]byte, []resolver.Endpoint, error) {\n\tpc, endpoints, err := buildPriorityConfig(priorities, xdsLBPolicy)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to build priority config: %v\", err)\n\t}\n\tret, err := json.Marshal(pc)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to marshal built priority config struct into json: %v\", err)\n\t}\n\treturn ret, endpoints, nil\n}\n\nfunc buildPriorityConfig(priorities []*priorityConfig, xdsLBPolicy *internalserviceconfig.BalancerConfig) (*priority.LBConfig, []resolver.Endpoint, error) {\n\tvar (\n\t\tretConfig    = &priority.LBConfig{Children: make(map[string]*priority.Child)}\n\t\tretEndpoints []resolver.Endpoint\n\t)\n\tfor _, p := range priorities {\n\t\tclusterUpdate := p.clusterConfig.Cluster\n\t\tswitch clusterUpdate.ClusterType {\n\t\tcase xdsresource.ClusterTypeEDS:\n\t\t\tnames, configs, endpoints, err := buildClusterImplConfigForEDS(p.childNameGen, p.clusterConfig, xdsLBPolicy)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, err\n\t\t\t}\n\t\t\tretConfig.Priorities = append(retConfig.Priorities, names...)","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/internal/xds/balancer/cdsbalancer/configbuilder.go#L85-L121","documentation":"Returned by buildPriorityConfigJSON (configbuilder.go:103) when json.Marshal(pc) fails on the priority.LBConfig struct that was just built successfully by buildPriorityConfig. The %v is the JSON marshalling error. Since the struct was constructed in-memory from validated types, a marshal failure indicates an internal type issue (e.g., a channel or function field, or a recursive struct). This is an internal invariant violation — the message is defensive.","triggerScenarios":"buildPriorityConfig returns a valid *priority.LBConfig (line 97), and json.Marshal is called on it (line 101). json.Marshal fails only if the struct contains unmarshallable types or hits a marshaler that errors. The priority.LBConfig and its children (clusterimpl.LBConfig, outlierdetection.LBConfig, internalserviceconfig.BalancerConfig) are all plain data structs with json tags, so marshal failure is unexpected.","commonSituations":"A code change that introduced an unmarshallable field type into the config struct tree. Version skew where the struct definition and the marshalling expectations diverge. Extremely unlikely in stock grpc-go.","solutions":["Check for version consistency across grpc-go packages in go.mod.","Inspect the wrapped %v — json.Marshal errors typically name the offending field/type.","If you forked any of the config structs, ensure all fields are JSON-compatible.","Report as a bug to grpc-go if using unmodified stock packages."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Internal invariant violation — json.Marshal on an in-memory struct.\n// Not actionable by user code; indicates version skew or code bug.\n// Check: go list -m all | grep grpc — all entries should match.","preventionTips":["Pin grpc-go to a single consistent version across all dependencies.","Avoid replace directives for grpc-go internal packages.","Run 'go mod tidy' after dependency changes."],"tags":["xds","json","marshal","config-builder","internal-invariant"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}