{"record":{"id":"073d831851c7fd8e","repo":"argoproj/argo-workflows","slug":"failed-to-marshal-evaluated-expression-w","errorCode":null,"errorMessage":"failed to marshal evaluated expression: %w","messagePattern":"failed to marshal evaluated expression: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/template/expression_template.go","lineNumber":266,"sourceCode":"\tresult, err := expr.Run(program, env)\n\tif (err != nil || result == nil) && (allowUnresolved || shouldAllowFailure) {\n\t\t//  <nil> result is also un-resolved, and any error can be unresolved\n\t\tlog.WithError(err).Debug(ctx, \"Result and error are unresolved\")\n\t\treturn fmt.Fprintf(w, \"{{%s%s}}\", kindExpression, expression)\n\t}\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to evaluate expression: %w\", err)\n\t}\n\tif result == nil {\n\t\treturn 0, fmt.Errorf(\"failed to evaluate expression %q\", expression)\n\t}\n\tresultMarshaled, err := json.Marshal(result)\n\tif (err != nil || resultMarshaled == nil) && allowUnresolved {\n\t\tlog.WithError(err).Debug(ctx, \"resultMarshaled is nil and unresolved is allowed \")\n\t\treturn fmt.Fprintf(w, \"{{%s%s}}\", kindExpression, expression)\n\t}\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to marshal evaluated expression: %w\", err)\n\t}\n\tif resultMarshaled == nil {\n\t\treturn 0, fmt.Errorf(\"failed to marshal evaluated marshaled expression %q\", expression)\n\t}\n\tmarshaledLength := len(resultMarshaled)\n\n\t// Trim leading and trailing quotes. The value is being inserted into something that's already a string.\n\tif len(resultMarshaled) > 1 && resultMarshaled[0] == '\"' && resultMarshaled[marshaledLength-1] == '\"' {\n\t\treturn w.Write(resultMarshaled[1 : marshaledLength-1])\n\t}\n\n\tresultQuoted := []byte(strconv.Quote(string(resultMarshaled)))\n\treturn w.Write(resultQuoted[1 : len(resultQuoted)-1])\n}\n\nfunc EnvMap(replaceMap map[string]string) map[string]any {\n\tenvMap := make(map[string]any)\n\tfor k, v := range replaceMap {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/util/template/expression_template.go#L248-L284","documentation":"After successful evaluation, json.Marshal of the expression's result failed — the evaluated value cannot be serialized to JSON for insertion into the template. Rare; indicates an unserializable value (e.g. chan, func, or cyclic structure) coming out of the expression.","triggerScenarios":"Thrown at util/template/expression_template.go:266 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Change the expression to return a JSON-serializable type","Avoid returning raw complex objects from custom contexts"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}