argoproj/argo-workflows · error
failed to evaluate workflow %s expression: %w
Error message
failed to evaluate workflow %s expression: %w
What it means
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.
Source
Thrown at server/event/dispatch/operation.go:218
for annotationKey, annotationValue := range metadata.Annotations {
evalAnnotation, err := o.evaluateStringExpression(annotationValue, fmt.Sprintf("annotation \"%s\"", annotationKey))
if err != nil {
return err
}
// See labels comment above.
if wf.Annotations == nil {
wf.Annotations = map[string]string{}
}
wf.Annotations[annotationKey] = evalAnnotation
}
return nil
}
func (o *Operation) evaluateStringExpression(statement string, errorInfo string) (string, error) {
env := exprenv.GetFuncMap(o.env)
program, err := expr.Compile(statement, expr.Env(env))
if err != nil {
return "", fmt.Errorf("failed to evaluate workflow %s expression: %w", errorInfo, err)
}
result, err := expr.Run(program, env)
if err != nil {
return "", fmt.Errorf("failed to evaluate workflow %s expression: %w", errorInfo, err)
}
v, ok := result.(string)
if !ok {
return "", fmt.Errorf("workflow %s expression must evaluate to a string, not a %T", errorInfo, result)
}
return v, nil
}
func expressionEnvironment(ctx context.Context, namespace, discriminator string, payload *wfv1.Item) (map[string]any, error) {
src := map[string]any{
"namespace": namespace,
"discriminator": discriminator,
"metadata": metaData(ctx),View on GitHub (pinned to 35bff19146)
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
Example fix
// before (typo + missing field)
workflowMetadata:
labels:
branch: paylod.body.repo.branch
// after
workflowMetadata:
labels:
branch: default("unknown", payload.body.repo.branch) Defensive patterns
Strategy: validation
Validate before calling
// Compile-check metadata expressions with the dispatch env before submitting
env := exprenv.GetFuncMap(dispatchEnv)
if _, err := expr.Compile(statement, expr.Env(env)); err != nil {
return fmt.Errorf("invalid workflowMetadata expression %q: %w", statement, err)
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- failed to compile workflow template parameter %s expression:
- failed to convert result to JSON "%s" expression: %w
- workflow %s expression must evaluate to a string, not a %T
- failed to evaluate workflow template parameter "%s" expressi
- single branch mode without a branch specified
AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03).
Data as JSON: /api/errors/eec33eb5211638ed.
Report an issue: GitHub.