argoproj/argo-workflows · error

failed to evaluate workflow template parameter "%s" expressi

Error message

failed to evaluate workflow template parameter "%s" expression: %w

What it means

The parameter expression compiled successfully but failed at runtime when expr.Run executed it against the dispatch environment. This happens for runtime errors: nil pointer/index into missing payload fields, type mismatches (e.g. arithmetic on a string), calling methods on null, or out-of-range access. The dispatch aborts and a Warning event is recorded on the binding.

Source

Thrown at server/event/dispatch/operation.go:155

		}

		// users will always want to know why a workflow was submitted,
		// so we label with creator (which is a standard) and the name of the triggering event
		//nolint: contextcheck
		creator.LabelCreator(o.ctx, wf)
		labels.Label(wf, common.LabelKeyWorkflowEventBinding, wfeb.Name)
		if submit.Arguments != nil {
			for _, p := range submit.Arguments.Parameters {
				if p.ValueFrom == nil {
					return nil, fmt.Errorf("malformed workflow template parameter \"%s\": valueFrom is nil", p.Name)
				}
				program, compileErr := expr.Compile(p.ValueFrom.Event, expr.Env(o.env))
				if compileErr != nil {
					return nil, fmt.Errorf("failed to compile workflow template parameter %s expression: %w", p.Name, compileErr)
				}
				result, runErr := expr.Run(program, o.env)
				if runErr != nil {
					return nil, fmt.Errorf("failed to evaluate workflow template parameter \"%s\" expression: %w", p.Name, runErr)
				}
				data, marshalErr := json.Marshal(result)
				if marshalErr != nil {
					return nil, fmt.Errorf("failed to convert result to JSON \"%s\" expression: %w", p.Name, marshalErr)
				}
				wf.Spec.Arguments.Parameters = append(wf.Spec.Arguments.Parameters, wfv1.Parameter{Name: p.Name, Value: wfv1.AnyStringPtr(wfv1.Item{Value: data})})
			}
		}
		wf, err = client.ArgoprojV1alpha1().Workflows(wfeb.Namespace).Create(ctx, wf, metav1.CreateOptions{})
		if err != nil {
			return nil, fmt.Errorf("failed to create workflow: %w", err)
		}
		return wf, nil
	}
	return nil, nil
}

func (o *Operation) populateWorkflowMetadata(wf *wfv1.Workflow, metadata *metav1.ObjectMeta) error {

View on GitHub (pinned to 35bff19146)

Solutions

  1. Add nil-safety with expr's `??` default operator or check existence: `payload.body ?? {}`, `payload.body.foo ?? 'default'`.
  2. Coerce types explicitly in the expression, e.g. `int(payload.count)` or `string(payload.id)`, to match expected operations.
  3. Log/inspect the actual payload: enable debug logging on the argo-server (it logs the env JSON at Debug level in Dispatch) or view the event payload from the eventsource, then align the expression paths.
  4. Update the WorkflowEventBinding to match the current payload schema and re-trigger the event to confirm dispatch succeeds.

Example fix

# before: crashes when body is missing
valueFrom:
  event: 'payload.body.message'
# after
valueFrom:
  event: '(payload.body ?? {}).message ?? ""'
Defensive patterns

Strategy: try-catch

Validate before calling

// harden expressions: defaults and type coercion
// valueFrom.event: '(payload.body ?? {}).message ?? ""'
// valueFrom.event: 'int(payload.count ?? 0)'

Try / catch

// in callers that trigger dispatch, tolerate per-binding failure and alert
if err := op.Dispatch(ctx); err != nil {
    logger.WithError(err).Error(ctx, "event dispatch failed")
    // surface via WorkflowEventBinding Warning event for operator visibility
}

Prevention

When it happens

Trigger: valueFrom.event performs operations on data absent from the actual event payload (e.g. `payload.body.foo` when body is null), assumes a numeric type where the payload delivered a string, or divides/indexes invalidly — triggered whenever an event with an unexpected shape matches the binding selector.

Common situations: Eventsource payload schema changed (field renamed/removed) while the binding still references the old path; webhook sent a different JSON shape than tested; JSON-normalized env turning expected numbers into strings; optional fields accessed without nil-guards.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/f611d27deae45ba2. Report an issue: GitHub.