{"record":{"id":"eec33eb5211638ed","repo":"argoproj/argo-workflows","slug":"failed-to-evaluate-workflow-s-expression-w","errorCode":null,"errorMessage":"failed to evaluate workflow %s expression: %w","messagePattern":"failed to evaluate workflow (.+?) expression: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/event/dispatch/operation.go","lineNumber":218,"sourceCode":"\tfor annotationKey, annotationValue := range metadata.Annotations {\n\t\tevalAnnotation, err := o.evaluateStringExpression(annotationValue, fmt.Sprintf(\"annotation \\\"%s\\\"\", annotationKey))\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t// See labels comment above.\n\t\tif wf.Annotations == nil {\n\t\t\twf.Annotations = map[string]string{}\n\t\t}\n\t\twf.Annotations[annotationKey] = evalAnnotation\n\t}\n\treturn nil\n}\n\nfunc (o *Operation) evaluateStringExpression(statement string, errorInfo string) (string, error) {\n\tenv := exprenv.GetFuncMap(o.env)\n\tprogram, err := expr.Compile(statement, expr.Env(env))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to evaluate workflow %s expression: %w\", errorInfo, err)\n\t}\n\tresult, err := expr.Run(program, env)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to evaluate workflow %s expression: %w\", errorInfo, err)\n\t}\n\n\tv, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"workflow %s expression must evaluate to a string, not a %T\", errorInfo, result)\n\t}\n\treturn v, nil\n}\n\nfunc expressionEnvironment(ctx context.Context, namespace, discriminator string, payload *wfv1.Item) (map[string]any, error) {\n\tsrc := map[string]any{\n\t\t\"namespace\":     namespace,\n\t\t\"discriminator\": discriminator,\n\t\t\"metadata\":      metaData(ctx),","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/server/event/dispatch/operation.go#L200-L236","documentation":"Raised by Operation.evaluateStringExpression when the workflowMetadata name/generateName/label/annotation expression from the EventBinding's submit.ObjectMeta either fails expr.Compile (syntax/type error) or expr.Run (runtime evaluation error). Compile and run failures are wrapped with the same message, distinguished only by the inner %w error text. It aborts dispatch because the workflow metadata cannot be populated.","triggerScenarios":"EventBinding submit.workflowMetadata contains name, generateName, labels, or annotations values that are invalid expr syntax (e.g. unbalanced quotes/parens) or reference unknown identifiers/functions at runtime (e.g. typo like `paylod.body.id`, calling a function not in exprenv.GetFuncMap, indexing a nil/absent payload field).","commonSituations":"Typo in the expression (`payload` misspelled, wrong body key); expression uses a field the sensor payload lacks (nil map access at runtime); using a sprig/expr function not available in the dispatch env; copy-pasting an expression from a CronWorkflow where the environment differs; quoting mistakes in YAML that mangle the expression.","solutions":["Read the wrapped %w error: compile errors point to syntax (fix quoting/parens in the YAML value), runtime errors point to unknown names or nil field access","Verify the expression only uses the dispatch environment: namespace, discriminator, metadata, payload (plus the expr/sprig func map), and that the payload path exists — e.g. `payload.body.id` not `payload.data.id`","Guard against missing payload fields with defaults: `default(\"unknown\", payload.body.id)` or existence checks","Test the expression locally with a sample payload using the same env before updating the EventBinding"],"exampleFix":"// before (typo + missing field)\nworkflowMetadata:\n  labels:\n    branch: paylod.body.repo.branch\n// after\nworkflowMetadata:\n  labels:\n    branch: default(\"unknown\", payload.body.repo.branch)","handlingStrategy":"validation","validationCode":"// Compile-check metadata expressions with the dispatch env before submitting\nenv := exprenv.GetFuncMap(dispatchEnv)\nif _, err := expr.Compile(statement, expr.Env(env)); err != nil {\n    return fmt.Errorf(\"invalid workflowMetadata expression %q: %w\", statement, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate EventBinding YAML with `argo lint` before applying","Only reference the documented env vars: namespace, discriminator, metadata, payload","Double-check YAML quoting of expressions — unquoted colons/braces corrupt the expression","Test expressions against a captured sample event payload"],"tags":["expr","expression-compile","event-dispatch","argo-workflows"],"backgroundTag":"expr-evaluation-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"}