{"record":{"id":"de270ba088caa4cd","repo":"knadh/listmonk","slug":"error-compiling-alt-plaintext-message-v","errorCode":null,"errorMessage":"error compiling alt plaintext message: %v","messagePattern":"error compiling alt plaintext message: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"models/campaigns.go","lineNumber":207,"sourceCode":"\tmsgTpl, err := template.New(ContentTpl).Funcs(f).Parse(body)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error compiling message: %v\", err)\n\t}\n\n\tout, err := baseTPL.AddParseTree(ContentTpl, msgTpl.Tree)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error inserting child template: %v\", err)\n\t}\n\tc.Tpl = out\n\n\tif hasTplExpr(c.AltBody.String) {\n\t\tb := c.AltBody.String\n\t\tfor _, r := range regTplFuncs {\n\t\t\tb = r.regExp.ReplaceAllString(b, r.replace)\n\t\t}\n\t\tbTpl, err := template.New(ContentTpl).Funcs(f).Parse(b)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error compiling alt plaintext message: %v\", err)\n\t\t}\n\t\tc.AltBodyTpl = bTpl\n\t}\n\n\t// Compile any header values that contain template expressions.\n\tfor _, set := range c.Headers {\n\t\tfor _, val := range set {\n\t\t\tif hasTplExpr(val) {\n\t\t\t\tc.HeaderTpls = make([]map[string]*txttpl.Template, len(c.Headers))\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif c.HeaderTpls != nil {\n\t\t\tbreak\n\t\t}\n\t}\n\tif c.HeaderTpls != nil {\n\t\tvar txtFuncs map[string]any = f","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/knadh/listmonk/blob/670c01717d48647093335cc23a6be6f4b79c3b6b/models/campaigns.go#L189-L225","documentation":"Compilation of the campaign's alternative plain-text message body failed during campaign preparation.","triggerScenarios":"AltBody is non-empty and contains template expressions (hasTplExpr true) with invalid syntax or unknown functions, so template.New(ContentTpl).Funcs(f).Parse(b) fails.","commonSituations":"Unbalanced {{ }} in the plaintext alt body; function typo; braces copied from HTML body with syntax invalid in text/template context; users often forget the alt body is also templated.","solutions":["Fix the syntax error reported in the wrapped parse error","Escape literal braces with {{\"{{\"}}\"","Validate alt body functions against the registered func map","Clear or simplify the alt body to confirm the error source"],"exampleFix":"// before\nalt = \"Hello {{ if .Name }}\"\n// after\nalt = \"Hello {{ if .Name }}{{ .Name }}{{ end }}\"","handlingStrategy":"validation","validationCode":"if hasTplExpr(c.AltBody.String) {\n    if _, err := template.New(\"alt\").Funcs(funcMap).Parse(c.AltBody.String); err != nil {\n        return fmt.Errorf(\"invalid alt body template: %v\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := c.CompileTemplate(); err != nil {\n    if strings.Contains(err.Error(), \"error compiling alt plaintext message\") {\n        // highlight the alt-body editor field with the parse error\n    }\n}","preventionTips":["Validate the alt body whenever the main body is validated","Escape braces in plaintext content","Preview both HTML and plaintext variants"],"tags":["template","go","campaign"],"backgroundTag":"template-parse-error","analyzedSha":"670c01717d48647093335cc23a6be6f4b79c3b6b","analyzedAt":"2026-09-01T03:39:35.452Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}