{"record":{"id":"5583c7a71adec26a","repo":"argoproj/argo-workflows","slug":"failed-to-marshal-patch-w","errorCode":null,"errorMessage":"failed to marshal patch: %w","messagePattern":"failed to marshal patch: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"workflow/controller/controller.go","lineNumber":1417,"sourceCode":"\terr = wfc.hydrator.Hydrate(ctx, wf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to hydrate workflow: %w\", err)\n\t}\n\tlogger := logging.RequireLoggerFromContext(ctx)\n\tlogger.WithFields(logging.Fields{\"namespace\": wf.Namespace, \"workflow\": wf.Name, \"uid\": wf.UID}).Info(ctx, \"archiving workflow\")\n\terr = wfc.wfArchive.ArchiveWorkflow(ctx, wf)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to archive workflow: %w\", err)\n\t}\n\tdata, err := json.Marshal(map[string]any{\n\t\t\"metadata\": metav1.ObjectMeta{\n\t\t\tLabels: map[string]string{\n\t\t\t\tcommon.LabelKeyWorkflowArchivingStatus: \"Archived\",\n\t\t\t},\n\t\t},\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal patch: %w\", err)\n\t}\n\t_, err = wfc.wfclientset.ArgoprojV1alpha1().Workflows(un.GetNamespace()).Patch(\n\t\tctx,\n\t\tun.GetName(),\n\t\ttypes.MergePatchType,\n\t\tdata,\n\t\tmetav1.PatchOptions{},\n\t)\n\tif err != nil {\n\t\t// from this point on we have successfully archived the workflow, and it is possible for the workflow to have actually\n\t\t// been deleted, so it's not a problem to get a `IsNotFound` error\n\t\tif apierr.IsNotFound(err) {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"failed to mark the workflow archived: %w\", err)\n\t}\n\treturn nil\n}","sourceCodeStart":1399,"sourceCodeEnd":1435,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/controller/controller.go#L1399-L1435","documentation":"In archiveWorkflowAux (workflow/controller/controller.go:1417), after successfully archiving, the controller builds a JSON merge patch setting the workflows.argoproj.io/archiving-status label to Archived. This error means json.Marshal of that tiny static map failed — practically unreachable with the hardcoded map (json.Marshal only fails on unsupported types), so it indicates an exotic build/runtime anomaly rather than a user-fixable condition.","triggerScenarios":"json.Marshal(map[string]any{\"metadata\": metav1.ObjectMeta{...}}) returns an error — with the fixed literal payload this should never happen; only conceivable via a corrupted standard library/runtime or if the literal was modified to include non-serializable values (channels/funcs) in a fork.","commonSituations":"Only in modified/forked code where the patch payload includes unsupported types; no real-world cluster configuration triggers it.","solutions":["If you forked and changed the patch payload, ensure all values are JSON-serializable (use string labels, plain maps).","Rebuild the controller binary from unmodified upstream sources.","If reproducible, capture the inner marshal error via the wrapped %w chain and file an issue."],"exampleFix":"// before (forked payload with unsupported type)\ndata, err := json.Marshal(map[string]any{\"metadata\": metav1.ObjectMeta{Labels: map[string]string{...}, ManagedFields: someFunc}})\n// after\nun, _ := signaling.ObjectMapper.ObjectToUnstructured(...)\ndata, err := json.Marshal(map[string]any{\"metadata\": metav1.ObjectMeta{Labels: map[string]string{common.LabelKeyWorkflowArchivingStatus: \"Archived\"}}})","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"data, err := json.Marshal(map[string]any{\n    \"metadata\": metav1.ObjectMeta{Labels: map[string]string{common.LabelKeyWorkflowArchivingStatus: \"Archived\"}},\n})\nif err != nil {\n    return fmt.Errorf(\"failed to marshal patch: %w\", err)\n}","preventionTips":["Keep the patch payload limited to JSON-serializable values (string label maps)","If forking, never embed funcs/channels/unserializable types in marshal targets","This path is effectively unreachable with upstream code; investigate build integrity if hit"],"tags":["json","serialization","archiving"],"backgroundTag":"json-marshal-failed","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}