{"record":{"id":"8409f97c98542193","repo":"kubernetes/kops","slug":"error-building-annotation-patch-v","errorCode":null,"errorMessage":"error building annotation patch: %v","messagePattern":"error building annotation patch: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/channels/channel_version.go","lineNumber":202,"sourceCode":"\tAnnotations map[string]string `json:\"annotations,omitempty\"`\n}\n\nfunc (c *Channel) SetInstalledVersion(ctx context.Context, k8sClient kubernetes.Interface, version *ChannelVersion) error {\n\t// Primarily to check it exists\n\t_, err := k8sClient.CoreV1().Namespaces().Get(ctx, c.Namespace, metav1.GetOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error querying namespace %q: %v\", c.Namespace, err)\n\t}\n\n\tvalue, err := version.Encode()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tannotationPatch := &annotationPatch{Metadata: annotationPatchMetadata{Annotations: map[string]string{c.AnnotationName(): value}}}\n\tannotationPatchJSON, err := json.Marshal(annotationPatch)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error building annotation patch: %v\", err)\n\t}\n\n\tklog.V(2).Infof(\"sending patch: %q\", string(annotationPatchJSON))\n\n\t_, err = k8sClient.CoreV1().Namespaces().Patch(ctx, c.Namespace, types.StrategicMergePatchType, annotationPatchJSON, metav1.PatchOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error applying annotation to namespace: %v\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":184,"sourceCodeEnd":213,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/channels/channel_version.go#L184-L213","documentation":"SetInstalledVersion builds a JSON strategic-merge patch containing only the annotations map, then applies it to the namespace. This error is thrown if json.Marshal of the in-memory annotationPatch struct fails. Since the struct is simple (map[string]string), this is rare and typically indicates an unexpected serialization problem.","triggerScenarios":"json.Marshal failing on the annotationPatch struct during SetInstalledVersion — practically only due to a programming-level issue, since the payload contains only strings.","commonSituations":"Rarely hit in practice; would surface as a bug in the patch construction code rather than a cluster/environment issue.","solutions":["Inspect the wrapped %v marshal error to identify the cause.","Verify the annotation value produced by version.Encode() is a plain string (no invalid content).","Upgrade/patch the library if a serialization bug is confirmed.","Report with the full wrapped error if reproducible."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := ch.SetInstalledVersion(ctx, k8sClient, version); err != nil {\n    if strings.Contains(err.Error(), \"error building annotation patch\") {\n        return fmt.Errorf(\"patch construction bug: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep channel version payloads as plain strings.","Test version.Encode() output in unit tests.","Report serialization failures upstream with full error text."],"tags":["kubernetes","json","serialization","patch"],"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"}