{"record":{"id":"488701d34ff1c8a8","repo":"argoproj/argo-workflows","slug":"failed-to-create-workflow-template-expression-envi","errorCode":null,"errorMessage":"failed to create workflow template expression environment: %w","messagePattern":"failed to create workflow template expression environment: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/event/dispatch/operation.go","lineNumber":49,"sourceCode":"\ntype Operation struct {\n\t//nolint: containedctx\n\tctx               context.Context\n\teventRecorder     record.EventRecorder\n\tinstanceIDService instanceid.Service\n\tevents            []wfv1.WorkflowEventBinding\n\tenv               map[string]any\n}\n\n// Context returns the context associated with this operation\nfunc (o *Operation) Context() context.Context {\n\treturn o.ctx\n}\n\nfunc NewOperation(ctx context.Context, instanceIDService instanceid.Service, eventRecorder record.EventRecorder, events []wfv1.WorkflowEventBinding, namespace, discriminator string, payload *wfv1.Item) (*Operation, error) {\n\tenv, err := expressionEnvironment(ctx, namespace, discriminator, payload)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create workflow template expression environment: %w\", err)\n\t}\n\treturn &Operation{\n\t\tctx:               ctx,\n\t\teventRecorder:     eventRecorder,\n\t\tinstanceIDService: instanceIDService,\n\t\tevents:            events,\n\t\tenv:               env,\n\t}, nil\n}\n\n// Dispatch executes the event dispatch. It is not to be converted with sutils;\n// the parent calling function should handle that responsibility.\nfunc (o *Operation) Dispatch(ctx context.Context) error {\n\tlogger := logging.RequireLoggerFromContext(ctx)\n\n\tlogger.Debug(ctx, \"Executing event dispatch\")\n\n\tdata, _ := json.MarshalIndent(o.env, \"\", \"  \")","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/server/event/dispatch/operation.go#L31-L67","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check binding selectors parse before posting events\nfor _, wfeb := range bindings {\n\tif _, err := expr.Eval(wfeb.Spec.Event.Selector, map[string]any{\"payload\": testPayload, \"discriminator\": \"x\"}); err != nil {\n\t\treturn fmt.Errorf(\"selector %q invalid: %w\", wfeb.Name, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"op, err := dispatch.NewOperation(ctx, instanceID, recorder, events, ns, disc, payload)\nif err != nil {\n\tlog.Errorf(\"operation setup failed: %v\", err) // inner error names the env failure\n\treturn err\n}","preventionTips":["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"],"tags":["events","expression","eventbinding","server"],"backgroundTag":"expression-environment-creation-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"}