{"record":{"id":"f4358833302d3401","repo":"argoproj/argo-workflows","slug":"failed-to-convert-result-to-json-s-expression","errorCode":null,"errorMessage":"failed to convert result to JSON \"%s\" expression: %w","messagePattern":"failed to convert result to JSON \"(.+?)\" expression: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/event/dispatch/operation.go","lineNumber":159,"sourceCode":"\t\t//nolint: contextcheck\n\t\tcreator.LabelCreator(o.ctx, wf)\n\t\tlabels.Label(wf, common.LabelKeyWorkflowEventBinding, wfeb.Name)\n\t\tif submit.Arguments != nil {\n\t\t\tfor _, p := range submit.Arguments.Parameters {\n\t\t\t\tif p.ValueFrom == nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"malformed workflow template parameter \\\"%s\\\": valueFrom is nil\", p.Name)\n\t\t\t\t}\n\t\t\t\tprogram, compileErr := expr.Compile(p.ValueFrom.Event, expr.Env(o.env))\n\t\t\t\tif compileErr != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to compile workflow template parameter %s expression: %w\", p.Name, compileErr)\n\t\t\t\t}\n\t\t\t\tresult, runErr := expr.Run(program, o.env)\n\t\t\t\tif runErr != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to evaluate workflow template parameter \\\"%s\\\" expression: %w\", p.Name, runErr)\n\t\t\t\t}\n\t\t\t\tdata, marshalErr := json.Marshal(result)\n\t\t\t\tif marshalErr != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to convert result to JSON \\\"%s\\\" expression: %w\", p.Name, marshalErr)\n\t\t\t\t}\n\t\t\t\twf.Spec.Arguments.Parameters = append(wf.Spec.Arguments.Parameters, wfv1.Parameter{Name: p.Name, Value: wfv1.AnyStringPtr(wfv1.Item{Value: data})})\n\t\t\t}\n\t\t}\n\t\twf, err = client.ArgoprojV1alpha1().Workflows(wfeb.Namespace).Create(ctx, wf, metav1.CreateOptions{})\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create workflow: %w\", err)\n\t\t}\n\t\treturn wf, nil\n\t}\n\treturn nil, nil\n}\n\nfunc (o *Operation) populateWorkflowMetadata(wf *wfv1.Workflow, metadata *metav1.ObjectMeta) error {\n\tif len(metadata.Name) > 0 {\n\t\tevalName, err := o.evaluateStringExpression(metadata.Name, \"name\")\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/server/event/dispatch/operation.go#L141-L177","documentation":"This error occurs in the Argo Workflows event dispatch (EventBinding -> Workflow submission) path when the result of evaluating a `valueFrom.event` expr-lang expression for an event-binding parameter cannot be serialized with json.Marshal. Argo stores each evaluated parameter as a JSON-encoded value in the created Workflow's arguments, so any expr value containing types JSON cannot represent (channels, funcs, NaN/Inf floats, unsupported maps) aborts the dispatch. The wrapped %w contains the exact json.MarshalUnsupportedTypeError.","triggerScenarios":"Dispatching an event via an EventBinding whose WorkflowTemplate reference declares an arguments parameter with valueFrom.event whose expr evaluation returns a value json.Marshal rejects — e.g. expr built-ins returning func values, NaN/Inf from arithmetic like `payload.x / 0` on floats, cyclic/odd-typed data embedded in the event payload, or a custom expr function registered in exprenv that returns a non-serializable Go type.","commonSituations":"Users write event expressions doing float division that yields +Inf/NaN; a sensor payload carries deeply unusual data that jsonutil.Jsonify did not normalize; a custom expr function (GetFuncMap extension) returns a Go func/channel; upgrading Argo changes the expr runtime so an expression that previously returned a string now returns a non-string type.","solutions":["Fix the valueFrom.event expression in the EventBinding/WorkflowTemplate so it returns a JSON-safe value, e.g. coerce with string(...) or sprig funcs instead of raw arithmetic that can produce NaN/Inf","Inspect the wrapped json.Marshal error (%w) to identify the offending field/type, then sanitize that field in the event payload before dispatch","If a custom expr function is at fault, change it to return only JSON-serializable types (string, number, bool, []any, map[string]any)","Validate the expression result with a pre-check in test: compile and run it with a sample payload and json.Marshal the result before deploying the binding"],"exampleFix":"// before (EventBinding parameter expression can yield +Inf)\nvalueFrom:\n  event: payload.data.a / payload.data.b\n// after\nvalueFrom:\n  event: string(payload.data.a / payload.data.b) # or guard: payload.data.b == 0 ? \"0\" : string(payload.data.a / payload.data.b)","handlingStrategy":"validation","validationCode":"// Test the binding expression offline before deploying\ndata, err := json.Marshal(exprResult)\nif err != nil {\n    return fmt.Errorf(\"binding expression result not JSON-serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep valueFrom.event expressions returning strings/numbers/bools/JSON-safe containers only","Avoid division or math that can produce NaN/Inf; coerce with string(...) or sprig defaults","Ensure custom expr functions in exprenv return JSON-serializable types","Unit-test each expression with a realistic payload and json.Marshal the result"],"tags":["event-dispatch","expr","json-marshal","argo-workflows"],"backgroundTag":"json-unsupported-type","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"}