{"record":{"id":"6815615feefc0606","repo":"knadh/listmonk","slug":"error-compiling-message-v","errorCode":null,"errorMessage":"error compiling message: %v","messagePattern":"error compiling message: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"models/campaigns.go","lineNumber":191,"sourceCode":"\t// If the format is markdown, convert Markdown to HTML.\n\tif c.ContentType == CampaignContentTypeMarkdown {\n\t\tvar b bytes.Buffer\n\t\tif err := markdown.Convert([]byte(c.Body), &b); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tbody = b.String()\n\t} else {\n\t\tbody = c.Body\n\t}\n\n\t// Compile the campaign message.\n\tfor _, r := range regTplFuncs {\n\t\tbody = r.regExp.ReplaceAllString(body, r.replace)\n\t}\n\n\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","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/knadh/listmonk/blob/670c01717d48647093335cc23a6be6f4b79c3b6b/models/campaigns.go#L173-L209","documentation":"Compilation of an individual message body from the campaign template failed while preparing the campaign for sending.","triggerScenarios":"CompileTemplate is called and template.New(ContentTpl).Funcs(f).Parse(body) fails because the campaign message body has invalid template actions or references unknown functions/fields.","commonSituations":"Same family as subject/base errors: stray \"{{\", misspelled function, wrong argument types to template funcs; often introduced after editing campaign content in the UI or via API import.","solutions":["Fix the invalid template expression reported in the wrapped error","Escape literal braces using {{\"{{\"}}\"","Ensure functions used are in the func map f registered with the template","Use previewTemplate to smoke-test the body before saving"],"exampleFix":"// before\n{{ .TrackLink | urlquery extraArg }}\n// after\n{{ .TrackLink | urlquery }}","handlingStrategy":"validation","validationCode":"if _, err := template.New(\"msg\").Funcs(funcMap).Parse(body); err != nil {\n    return fmt.Errorf(\"invalid message template: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := c.CompileTemplate(); err != nil {\n    if strings.Contains(err.Error(), \"error compiling message\") {\n        // surface the wrapped parse error to the content editor\n    }\n}","preventionTips":["Check function arity and names against the func map","Test render with sample data before activating a campaign","Keep body free of {{ define }} blocks that can break tree insertion"],"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"}