{"record":{"id":"5c7b9184ec8a51b2","repo":"knadh/listmonk","slug":"campaigns-fieldinvalidname-5c7b91","errorCode":null,"errorMessage":"campaigns.fieldInvalidName","messagePattern":"campaigns\\.fieldInvalidName","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/templates.go","lineNumber":216,"sourceCode":"\n// DeleteTemplate handles template deletion.\nfunc (a *App) DeleteTemplate(c echo.Context) error {\n\t// Delete the template from the DB.\n\tid := getID(c)\n\tif err := a.core.DeleteTemplate(id); err != nil {\n\t\treturn err\n\t}\n\n\t// Delete cached in-memory template.\n\ta.manager.DeleteTpl(id)\n\n\treturn c.JSON(http.StatusOK, okResp{true})\n}\n\n// compileTemplate validates template fields.\nfunc (a *App) validateTemplate(o models.Template) error {\n\tif !strHasLen(o.Name, 1, stdInputMaxLen) {\n\t\treturn errors.New(a.i18n.T(\"campaigns.fieldInvalidName\"))\n\t}\n\n\tif o.Type == models.TemplateTypeCampaign && !regexpTplTag.MatchString(o.Body) {\n\t\treturn echo.NewHTTPError(http.StatusBadRequest,\n\t\t\ta.i18n.Ts(\"templates.placeholderHelp\", \"placeholder\", tplTag))\n\t}\n\n\tif o.Type == models.TemplateTypeTx && strings.TrimSpace(o.Subject) == \"\" {\n\t\treturn echo.NewHTTPError(http.StatusBadRequest,\n\t\t\ta.i18n.Ts(\"globals.messages.missingFields\", \"name\", \"subject\"))\n\t}\n\n\treturn nil\n}\n\n// previewTemplate renders the HTML preview of a template.\nfunc (a *App) previewTemplate(tpl models.Template) ([]byte, error) {\n\tvar out []byte","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/knadh/listmonk/blob/670c01717d48647093335cc23a6be6f4b79c3b6b/cmd/templates.go#L198-L234","documentation":"validateTemplate in cmd/templates.go requires a template's name to pass strHasLen(o.Name, 1, stdInputMaxLen), returning the campaigns.fieldInvalidName key on failure. Template names must be non-empty and within the standard input length, mirroring the campaign name rule.","triggerScenarios":"CreateTemplate or UpdateTemplate (POST/PUT /api/templates) with a name that is missing, empty, or longer than stdInputMaxLen characters.","commonSituations":"API calls built from form data where the name input was left blank; imports of templates from external tools whose long titles exceed the cap; automation that sets name: null.","solutions":["Supply a non-empty name within stdInputMaxLen characters.","Truncate long imported titles to the limit before calling the API.","In clients, require the name field and cap its length before submission."],"exampleFix":"// before\n{\"name\": null, \"body\": \"{{ template \"content\" . }}\"}\n// after\n{\"name\": \"Default campaign template\", \"body\": \"{{ template \"content\" . }}\"}","handlingStrategy":"validation","validationCode":"function validateTemplateName(name) {\n  if (typeof name !== 'string' || name.trim().length === 0 || name.length > 200 /* stdInputMaxLen */) {\n    throw new Error('template name must be 1-200 characters');\n  }\n}","typeGuard":"function hasValidTemplateName(v: unknown): v is string {\n  return typeof v === 'string' && v.length >= 1 && v.length <= 200;\n}","tryCatchPattern":"try {\n  await api.createTemplate({ name, body });\n} catch (e) {\n  if (e.message.includes('fieldInvalidName')) {\n    throw new Error('Template name is required (max ~200 chars)');\n  }\n  throw e;\n}","preventionTips":["Require the name field in template creation UIs and scripts.","Truncate imported template titles to the length cap.","Reject whitespace-only names before calling the API."],"tags":["validation","template","input-length"],"backgroundTag":"missing-required-argument","analyzedSha":"670c01717d48647093335cc23a6be6f4b79c3b6b","analyzedAt":"2026-09-01T03:39:35.452Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}