{"record":{"id":"574be7da62ca5a50","repo":"argoproj/argo-workflows","slug":"failed-to-convert-the-podspecpatch-yaml-to-json","errorCode":null,"errorMessage":"Failed to convert the PodSpecPatch yaml to json","messagePattern":"Failed to convert the PodSpecPatch yaml to json","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/util/util.go","lineNumber":1689,"sourceCode":"\t\tif err != nil {\n\t\t\treturn str, err\n\t\t}\n\t\treturn string(jsonStr), nil\n\t}\n\treturn str, nil\n}\n\nfunc ApplyPodSpecPatch(podSpec apiv1.PodSpec, podSpecPatchYamls ...string) (*apiv1.PodSpec, error) {\n\tpodSpecJSON, err := json.Marshal(podSpec)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"\", \"Failed to marshal the Pod spec\")\n\t}\n\n\tfor _, podSpecPatchYaml := range podSpecPatchYamls {\n\t\t// must convert to json because PodSpec has only json tags\n\t\tpodSpecPatchJSON, convertErr := ConvertYAMLToJSON(podSpecPatchYaml)\n\t\tif convertErr != nil {\n\t\t\treturn nil, errors.Wrap(convertErr, \"\", \"Failed to convert the PodSpecPatch yaml to json\")\n\t\t}\n\n\t\t// validate the patch to be a PodSpec\n\t\tif unmarshalErr := json.Unmarshal([]byte(podSpecPatchJSON), &apiv1.PodSpec{}); unmarshalErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid podSpecPatch %q: %w\", podSpecPatchYaml, unmarshalErr)\n\t\t}\n\n\t\tpodSpecJSON, err = strategicpatch.StrategicMergePatch(podSpecJSON, []byte(podSpecPatchJSON), apiv1.PodSpec{})\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"\", \"Error occurred during strategic merge patch\")\n\t\t}\n\t}\n\n\tvar newPodSpec apiv1.PodSpec\n\terr = json.Unmarshal(podSpecJSON, &newPodSpec)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"\", \"Error in Unmarshalling after merge the patch\")\n\t}","sourceCodeStart":1671,"sourceCodeEnd":1707,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/util/util.go#L1671-L1707","documentation":"ApplyPodSpecPatch accepts podSpecPatch values as YAML (workflow fields allow YAML there) and converts each to JSON via ConvertYAMLToJSON before strategic-merging, because PodSpec only carries JSON tags. If the YAML→JSON conversion fails — malformed YAML syntax, invalid types, or content that isn't a valid mapping — the underlying convert error is returned wrapped as \"Failed to convert the PodSpecPatch yaml to json\".","triggerScenarios":"Calling ApplyPodSpecPatch (used by the controller when applying spec.podSpecPatch, workflow-level podMetadata patches, etc.) with a podSpecPatch string that is not well-formed YAML or has a type error (e.g. a scalar where a map is required, tabs for indentation).","commonSituations":"Hand-editing podSpecPatch in workflow YAML with tabs or bad indentation; passing a JSON string with syntax errors; templating mistakes that inject empty or partially-rendered text into podSpecPatch; quoting issues when the patch is passed through environment variables or CLI flags.","solutions":["Validate the patch text with a YAML parser (e.g. `yq . podspec-patch.yaml`) and fix syntax errors — remember tabs are illegal in YAML.","Ensure the patch is a mapping at top level (keys like spec.containers...), not a scalar or list.","Test the patch locally with `argo lint` or a minimal workflow before applying to production."],"exampleFix":"# before\npodSpecPatch: |\n\tcontainers:        # tab indentation -> YAML parse error\n\t- name: main\n# after\npodSpecPatch: |\n  containers:        # spaces only\n    - name: main","handlingStrategy":"validation","validationCode":"# shell: validate the patch is well-formed YAML before submitting\nyq eval '.' podspec-patch.yaml > /dev/null || { echo \"podSpecPatch is not valid YAML\"; exit 1; }\n# Go: same check in-process\nif _, err := util.ConvertYAMLToJSON(patch); err != nil {\n\treturn fmt.Errorf(\"podSpecPatch not convertible: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go: surface the exact YAML failure to the user\nif _, err := util.ApplyPodSpecPatch(podSpec, patchYaml); err != nil {\n\tif strings.Contains(err.Error(), \"Failed to convert the PodSpecPatch yaml to json\") {\n\t\treturn fmt.Errorf(\"fix podSpecPatch YAML syntax (no tabs, mapping at top level): %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Lint podSpecPatch YAML with yq or `argo lint` before submission.","Use spaces, never tabs, in YAML patches.","Keep patches as top-level mappings keyed by PodSpec fields.","When templating patches, assert the rendered output is non-empty and parses."],"tags":["yaml","json","podspec","patch"],"backgroundTag":"yaml-parse-error","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"}