{"record":{"id":"cf380246b1e7b9d5","repo":"knadh/listmonk","slug":"campaigns-fieldinvalidbody","errorCode":null,"errorMessage":"campaigns.fieldInvalidBody","messagePattern":"campaigns\\.fieldInvalidBody","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/campaigns.go","lineNumber":733,"sourceCode":"\t\t}\n\t}\n\n\tif len(c.ListIDs) == 0 {\n\t\treturn c, errors.New(a.i18n.T(\"campaigns.fieldInvalidListIDs\"))\n\t}\n\n\tif !a.manager.HasMessenger(c.Messenger) {\n\t\t// If it's a specific SMTP, but it's no longer available (removed/disabled), fall back to general email messenger.\n\t\tif strings.HasPrefix(c.Messenger, \"email-\") {\n\t\t\tc.Messenger = \"email\"\n\t\t} else {\n\t\t\treturn c, errors.New(a.i18n.Ts(\"campaigns.fieldInvalidMessenger\", \"name\", c.Messenger))\n\t\t}\n\t}\n\n\tcamp := models.Campaign{Body: c.Body, TemplateBody: tplTag}\n\tif err := c.CompileTemplate(a.manager.TemplateFuncs(&camp)); err != nil {\n\t\treturn c, errors.New(a.i18n.Ts(\"campaigns.fieldInvalidBody\", \"error\", err.Error()))\n\t}\n\n\tif len(c.Headers) == 0 {\n\t\tc.Headers = make([]map[string]string, 0)\n\t}\n\n\t// Validate and initialize attribs.\n\tif c.Attribs != nil {\n\t\tif _, err := json.Marshal(c.Attribs); err != nil {\n\t\t\treturn c, errors.New(a.i18n.T(\"subscribers.invalidJSON\"))\n\t\t}\n\t}\n\n\tif len(c.ArchiveMeta) == 0 {\n\t\tc.ArchiveMeta = json.RawMessage(\"{}\")\n\t}\n\n\tif c.ArchiveSlug.String != \"\" {","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/knadh/listmonk/blob/670c01717d48647093335cc23a6be6f4b79c3b6b/cmd/campaigns.go#L715-L751","documentation":"validateCampaignFields compiles the campaign body as a Go template via c.CompileTemplate(a.manager.TemplateFuncs(&camp)); any template parse/compile failure becomes campaigns.fieldInvalidBody with the underlying error interpolated. It guards against invalid template syntax or references to undefined template functions.","triggerScenarios":"Campaign body containing malformed Go template syntax (unclosed {{ }}, bad pipelines) or calling template functions that don't exist in the manager's TemplateFuncs, on create/update/test campaign calls.","commonSituations":"Pasting HTML with stray '{{' characters (e.g. CSS/JS or Angular/Vue bindings) that Go templates try to parse; typos in custom template function names; template tags from another system (Handlebars {{#if}}) used verbatim.","solutions":["Fix the template syntax reported in the interpolated error message — typically an unclosed {{ }} or bad expression.","Escape literal braces not meant as templates (e.g. use {{ \"{{\" }} or avoid them) in CSS/JS or Angular-style code.","Replace unknown function calls with ones registered in TemplateFuncs (e.g. use built-in newsletter functions).","Compile the body locally with text/template and the same func map to reproduce the exact parse error before submitting."],"exampleFix":"// before\n{\"body\": \"<div ng-if=\"{{user.active}}\">Hi</div>\"}\n// after\n{\"body\": \"<div data-active=\"{{ if .Subscriber.Status }}1{{ end }}\">Hi</div>\"}","handlingStrategy":"try-catch","validationCode":"// pre-compile the body with Go's text/template rules before calling the API\n// (in Go)\n_, err := template.New(\"body\").Funcs(myFuncs).Parse(campaignBody)\nif err != nil {\n    return fmt.Errorf(\"campaign body template error: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.createCampaign({ body, ...rest });\n} catch (e) {\n  if (e.message.includes('fieldInvalidBody')) {\n    // e.message embeds the underlying Go template error\n    throw new Error(`Fix campaign body template: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Test template bodies on a test campaign before production sends.","Escape literal '{{' in CSS/JS content that should not be templated.","Only call template functions registered by the app; check docs for the list.","Keep templates from other engines (Handlebars, Vue) out of campaign bodies."],"tags":["template","campaign","go-template","validation"],"backgroundTag":"go-template-parse-error","analyzedSha":"670c01717d48647093335cc23a6be6f4b79c3b6b","analyzedAt":"2026-09-01T03:39:35.452Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}