{"record":{"id":"09c786e5053afb93","repo":"kubernetes/kops","slug":"error-building-node-patch-v","errorCode":null,"errorMessage":"error building node patch: %v","messagePattern":"error building node patch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops-controller/controllers/node_controller.go","lineNumber":161,"sourceCode":"// patchNodeLabels patches the node labels to set the specified labels\nfunc patchNodeLabels(client *corev1client.CoreV1Client, ctx context.Context, node *corev1.Node, setLabels map[string]string, deleteLabels map[string]struct{}) error {\n\tnodePatchMetadata := &nodePatchMetadata{\n\t\tLabels: make(map[string]*string),\n\t}\n\tfor k, v := range setLabels {\n\t\tv := v\n\t\tnodePatchMetadata.Labels[k] = &v\n\t}\n\tfor k := range deleteLabels {\n\t\tnodePatchMetadata.Labels[k] = nil\n\t}\n\n\tnodePatch := &nodePatch{\n\t\tMetadata: nodePatchMetadata,\n\t}\n\tnodePatchJson, err := json.Marshal(nodePatch)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error building node patch: %v\", err)\n\t}\n\n\tklog.V(2).Infof(\"sending patch for node %q: %q\", node.Name, string(nodePatchJson))\n\n\t_, err = client.Nodes().Patch(ctx, node.Name, types.StrategicMergePatchType, nodePatchJson, metav1.PatchOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error applying patch to node: %v\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":143,"sourceCodeEnd":173,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops-controller/controllers/node_controller.go#L143-L173","documentation":"patchNodeLabels marshals a strategic-merge patch (labels map with null for deletions) to JSON before sending it; this wraps json.Marshal failing. The patch structure is built from simple label maps, so a failure here signals an internal bug rather than bad input.","triggerScenarios":"json.Marshal(nodePatch) returns an error — practically only if the patch struct contains an unsupported value (e.g. a channel, func, or unmarshalable type added to nodePatch).","commonSituations":"Extremely rare with the stock struct; would appear if a contributor added a field with a non-serializable type or a bad custom MarshalJSON.","solutions":["Read the wrapped %v error to see the offending field/type","Remove or fix the unmarshalable field in the nodePatch struct","Verify all fields have JSON-compatible types and tags"],"exampleFix":"// before\nPatch Metadata map[string]interface{} `json:\"metadata\"` // may hold funcs\n// after\nPatch Metadata *nodePatchMetadata `json:\"metadata,omitempty\"`","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(nodePatch); err != nil {\n\treturn fmt.Errorf(\"error building node patch: %v\", err)\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep nodePatch fields JSON-serializable with explicit json tags","Add a unit test marshalling nodePatch","Avoid interface{} fields that can hold funcs/channels"],"tags":["kubernetes","serialization","json","node-controller"],"backgroundTag":"json-marshal-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}