{"record":{"id":"13247de1022f412a","repo":"argoproj/argo-workflows","slug":"failed-to-substitute-configmapkeyref-w","errorCode":null,"errorMessage":"failed to substitute configMapKeyRef: %w","messagePattern":"failed to substitute configMapKeyRef: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/common/util.go","lineNumber":267,"sourceCode":"\t\t\tartifacts[i] = *argArt\n\t\t\tartifacts[i].Path = inArt.Path\n\t\t\tartifacts[i].Mode = inArt.Mode\n\t\t\tartifacts[i].RecurseMode = inArt.RecurseMode\n\t\t}\n\t}\n\n\treturn SubstituteParams(ctx, newTmpl, globalParams, localParams)\n}\n\n// substituteConfigMapKeyRefParam performs template substitution for ConfigMapKeyRef\nfunc substituteConfigMapKeyRefParam(ctx context.Context, in string, replaceMap map[string]any) (string, error) {\n\ttmpl, err := template.NewTemplate(in)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treplacedString, err := tmpl.Replace(ctx, replaceMap, false)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to substitute configMapKeyRef: %w\", err)\n\t}\n\treturn replacedString, nil\n}\n\n// SubstituteParams returns a new copy of the template with global, pod, and input parameters substituted\nfunc SubstituteParams(ctx context.Context, tmpl *wfv1.Template, globalParams, localParams Parameters) (*wfv1.Template, error) {\n\ttmplBytes, err := json.Marshal(tmpl)\n\tif err != nil {\n\t\treturn nil, errors.InternalWrapError(err)\n\t}\n\t// First replace globals & locals, then replace inputs because globals could be referenced in the inputs\n\treplaceMap := template.ToAnyMap(globalParams.Merge(localParams))\n\tglobalReplacedTmplStr, err := template.Replace(ctx, string(tmplBytes), replaceMap, true)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar globalReplacedTmpl wfv1.Template\n\terr = json.Unmarshal([]byte(globalReplacedTmplStr), &globalReplacedTmpl)","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/common/util.go#L249-L285","documentation":"substituteConfigMapKeyRefParam resolves `{{workflow.parameters.X}}`-style expressions backed by a configMapKeyRef by first building a template and then running tmpl.Replace to substitute values. Any failure during that substitution (unresolvable variable, malformed template expression) is wrapped as 'failed to substitute configMapKeyRef: %w' so callers know the configMap parameter substitution stage failed.","triggerScenarios":"A workflow parameter/cron spec contains a configMapKeyRef whose value template references variables that cannot be resolved at substitute time, or the raw input (`in`) is not a valid template (template.NewTemplate fails), or tmpl.Replace encounters an undefined/ill-formed expression in replaceMap keys.","commonSituations":"Referencing a global parameter inside a configMapKeyRef value before it exists; typos like `{{workflow.name` (unclosed braces); submitting a CronWorkflow whose `when`/parameter expressions reference the schedule or event placeholders that aren't populated; calling SubstituteParams with local params missing a referenced key.","solutions":["Read the wrapped inner error (%w chain) to find the exact unresolvable variable and fix the expression in the template/parameter","Ensure the referenced ConfigMap key exists and its value contains only resolvable expressions (see error 540 for the label requirement)","Validate the workflow with `argo lint` before submitting to catch malformed template expressions","Check that all replaceMap parameters (global + local) are actually provided in spec.arguments"],"exampleFix":"# before\nvalue: \"{{workflow.parameters.missingParam}}/path\"\n# after\nvalue: \"{{workflow.parameters.definedParam}}/path\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"replaced, err := common.SubstituteParams(ctx, tmpl, globalParams, localParams)\nif err != nil {\n    return fmt.Errorf(\"configMapKeyRef substitution failed: %w\", err) // inspect %w chain for the bad expression\n}","preventionTips":["Run `argo lint` on workflows and cron workflows before submitting","Keep configMapKeyRef values free of references to undefined parameters","Ensure all global params referenced in substitution maps are supplied in spec.arguments"],"tags":["template","substitution","parameters","argo-workflows"],"backgroundTag":"template-substitution-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"}