{"record":{"id":"62abf7d55760db3c","repo":"argoproj/argo-workflows","slug":"failed-to-marshal-evaluated-marshaled-expression","errorCode":null,"errorMessage":"failed to marshal evaluated marshaled expression %q","messagePattern":"failed to marshal evaluated marshaled expression %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/template/expression_template.go","lineNumber":269,"sourceCode":"\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 {\n\t\tenvMap[k] = v\n\t}\n\treturn envMap","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/util/template/expression_template.go#L251-L287","documentation":"Final guard in expressionReplaceCore: json.Marshal either failed or produced nil after evaluation, which should not be reachable when the earlier allowUnresolved branches ran. Seeing it means an internal inconsistency between the marshal result and the error state.","triggerScenarios":"Thrown at util/template/expression_template.go:269 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Report as a bug with the workflow and expression that triggered it","Work around by simplifying the expression's return type"],"exampleFix":null,"handlingStrategy":"fallback","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"}