{"record":{"id":"53b5627f74feb33b","repo":"tailscale/tailscale","slug":"error-marshalling-updated-owner-references-w","errorCode":null,"errorMessage":"error marshalling updated owner references: %w","messagePattern":"error marshalling updated owner references: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/k8s-operator/ingress-for-pg.go","lineNumber":929,"sourceCode":"\t}\n\n\to, err := parseOwnerAnnotation(svc)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif o == nil || len(o.OwnerRefs) == 0 {\n\t\treturn nil, fmt.Errorf(\"Tailscale Service %s exists, but does not contain owner annotation with owner references; not proceeding as this is likely a resource created by something other than the Tailscale Kubernetes operator\", svc.Name)\n\t}\n\tif slices.Contains(o.OwnerRefs, ref) { // up to date\n\t\treturn svc.Annotations, nil\n\t}\n\tif o.OwnerRefs[0].Resource != nil {\n\t\treturn nil, fmt.Errorf(\"Tailscale Service %s is owned by another resource: %#v; cannot be reused for an Ingress\", svc.Name, o.OwnerRefs[0].Resource)\n\t}\n\to.OwnerRefs = append(o.OwnerRefs, ref)\n\tjson, err := json.Marshal(o)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshalling updated owner references: %w\", err)\n\t}\n\n\tnewAnnots := make(map[string]string, len(svc.Annotations)+1)\n\tmaps.Copy(newAnnots, svc.Annotations)\n\tnewAnnots[ownerAnnotation] = string(json)\n\treturn newAnnots, nil\n}\n\n// parseOwnerAnnotation returns nil if no valid owner found.\nfunc parseOwnerAnnotation(tsSvc *tailscale.VIPService) (*ownerAnnotationValue, error) {\n\tif tsSvc == nil {\n\t\treturn nil, nil\n\t}\n\n\tif tsSvc.Annotations == nil || tsSvc.Annotations[ownerAnnotation] == \"\" {\n\t\treturn nil, nil\n\t}\n\to := &ownerAnnotationValue{}","sourceCodeStart":911,"sourceCodeEnd":947,"githubUrl":"https://github.com/tailscale/tailscale/blob/cfe32b8be6a33f8e24fbc369cbfbf7c729d9e042/cmd/k8s-operator/ingress-for-pg.go#L911-L947","documentation":"Defensive error if json.Marshal of the updated ownerAnnotationValue (original refs plus the appended {OperatorID} ref) fails. The struct contains only strings and a pointer-to-struct Resource field, so encoding/json cannot realistically fail. Practically unreachable; surfaced only to satisfy the error contract.","triggerScenarios":"ownerAnnotations() after o.OwnerRefs = append(o.OwnerRefs, ref) — no realistic trigger; marshalling a slice of string-bearing structs.","commonSituations":"Not observed in practice; would require memory corruption or a fork adding unmarshalable types.","solutions":["Treat as an upstream bug if reproducible and report it with the wrapped error","Check custom builds for modifications to OwnerRef/ownerAnnotationValue types"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"data, err := json.Marshal(o)\nif err != nil {\n    // unreachable for this struct; fail loudly and report upstream\n    return nil, fmt.Errorf(\"error marshalling updated owner references: %w\", err)\n}","preventionTips":["Keep OwnerRef fields limited to JSON-serializable types in custom builds","Add unit tests around ownerAnnotations if you extend the ownership schema"],"tags":["json","defensive-check","unreachable"],"backgroundTag":null,"analyzedSha":"cfe32b8be6a33f8e24fbc369cbfbf7c729d9e042","analyzedAt":"2026-08-15T19:58:31.583Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}