{"record":{"id":"3c7becc71943fbbf","repo":"argoproj/argo-workflows","slug":"cannot-finish-template-replacement-because-the-res","errorCode":null,"errorMessage":"cannot finish template replacement because the result was invalid JSON","messagePattern":"cannot finish template replacement because the result was invalid JSON","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/template/replace.go","lineNumber":56,"sourceCode":"// entry marks an absent optional (a skipped/omitted node's output with no default), and a simple\n// tag resolving to nil is a terminal error regardless of allowUnresolved, which only governs tags\n// whose key is missing entirely.\nfunc Replace(ctx context.Context, s string, replaceMap map[string]any, allowUnresolved bool) (string, error) {\n\tif !json.Valid([]byte(s)) {\n\t\treturn \"\", errors.New(\"cannot do template replacements with invalid JSON\")\n\t}\n\n\tt, err := NewTemplate(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treplacedString, err := t.Replace(ctx, replaceMap, allowUnresolved)\n\tif err != nil {\n\t\treturn s, err\n\t}\n\n\tif !json.Valid([]byte(replacedString)) {\n\t\treturn s, errors.New(\"cannot finish template replacement because the result was invalid JSON\")\n\t}\n\n\treturn replacedString, nil\n}\n\n// ReplaceStrictAny behaves like Replace but enforces that tags starting with any of strictPrefixes\n// MUST be resolved, even if allowUnresolved behavior is otherwise active (implicit). It takes raw\n// values, preserving nil entries so that expression tags can distinguish an absent (nil) value from\n// an empty string (e.g. via `??`). A simple tag resolving to a nil value is a terminal error (not a\n// missing-variable error): an absent optional must be handled by a producer default, a consumer\n// input default (dropping the argument before substitution), or an expression fallback.\nfunc ReplaceStrictAny(ctx context.Context, s string, replaceMap map[string]any, strictPrefixes []string) (string, error) {\n\tif !json.Valid([]byte(s)) {\n\t\treturn \"\", errors.New(\"cannot do template replacements with invalid JSON\")\n\t}\n\n\tt, err := NewTemplate(s)\n\tif err != nil {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/util/template/replace.go#L38-L74","documentation":"After tag substitution succeeded, the result string failed a final json.Valid check in Replace — a replaced value injected content (e.g. unescaped quotes or braces) that broke the JSON structure that was valid going in.","triggerScenarios":"Thrown at util/template/replace.go:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["JSON-escape or properly quote the substituted parameter values","Check parameter values for raw quotes/newlines injected into JSON fields"],"exampleFix":null,"handlingStrategy":"validation","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"}