argoproj/argo-workflows · error
failed to create workflow template expression environment: %
Error message
failed to create workflow template expression environment: %w
What it means
NewOperation builds an expression environment (env) used to evaluate WorkflowEventBinding selectors; it loads config maps / context data for the namespace, discriminator and payload. If constructing that environment fails (e.g. the underlying expressionEnvironment call errors fetching dependencies), the operation cannot be created and the raw error is wrapped with this message. ReceiveEvent propagates it to the event dispatch path.
Source
Thrown at server/event/dispatch/operation.go:49
type Operation struct {
//nolint: containedctx
ctx context.Context
eventRecorder record.EventRecorder
instanceIDService instanceid.Service
events []wfv1.WorkflowEventBinding
env map[string]any
}
// Context returns the context associated with this operation
func (o *Operation) Context() context.Context {
return o.ctx
}
func NewOperation(ctx context.Context, instanceIDService instanceid.Service, eventRecorder record.EventRecorder, events []wfv1.WorkflowEventBinding, namespace, discriminator string, payload *wfv1.Item) (*Operation, error) {
env, err := expressionEnvironment(ctx, namespace, discriminator, payload)
if err != nil {
return nil, fmt.Errorf("failed to create workflow template expression environment: %w", err)
}
return &Operation{
ctx: ctx,
eventRecorder: eventRecorder,
instanceIDService: instanceIDService,
events: events,
env: env,
}, nil
}
// Dispatch executes the event dispatch. It is not to be converted with sutils;
// the parent calling function should handle that responsibility.
func (o *Operation) Dispatch(ctx context.Context) error {
logger := logging.RequireLoggerFromContext(ctx)
logger.Debug(ctx, "Executing event dispatch")
data, _ := json.MarshalIndent(o.env, "", " ")View on GitHub (pinned to 35bff19146)
Solutions
- Check argo-server logs for the wrapped inner error — it names the true cause (env construction step).
- Verify the event payload is valid JSON and matches what your WorkflowEventBinding selectors expect.
- Test the binding with `argo events test <wfeb-name> --payload '...'` to reproduce locally.
- Ensure the namespace has correctly configured WorkflowEventBinding spec.event.selector expressions.
- Confirm argo-server is healthy and can access the cluster (auth.GetWfClient dependencies) before dispatching events.
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check binding selectors parse before posting events
for _, wfeb := range bindings {
if _, err := expr.Eval(wfeb.Spec.Event.Selector, map[string]any{"payload": testPayload, "discriminator": "x"}); err != nil {
return fmt.Errorf("selector %q invalid: %w", wfeb.Name, err)
}
} Try / catch
op, err := dispatch.NewOperation(ctx, instanceID, recorder, events, ns, disc, payload)
if err != nil {
log.Errorf("operation setup failed: %v", err) // inner error names the env failure
return err
} Prevention
- Send well-formed JSON event payloads matching your selectors
- Test bindings with `argo events test` before wiring real webhooks
- Keep argo-server's cluster client/RBAC healthy for the namespace
- Log the full wrapped error chain to find the true env failure
When it happens
Trigger: Calling ReceiveEvent on the /api/v1/events/{namespace}/{discriminator} endpoint when expressionEnvironment fails — e.g. invalid payload item type, or errors resolving env/config data the environment depends on in the server's context.
Common situations: Posting event payloads with data the expression env builder cannot process; server-side context misconfiguration (missing client in ctx for the namespace); custom event discriminators with unexpected payload shapes.
Related errors
- failed to evaluate workflow template expression: %w
- failed to dispatch event: %v
- getting archived workflows not supported
- getting archived workflow for estimator not supported
- deleting archived workflows not supported
AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03).
Data as JSON: /api/errors/488701d34ff1c8a8.
Report an issue: GitHub.