knadh/listmonk · error
campaigns.fieldInvalidName
Error message
campaigns.fieldInvalidName
What it means
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.
Source
Thrown at cmd/templates.go:216
// DeleteTemplate handles template deletion.
func (a *App) DeleteTemplate(c echo.Context) error {
// Delete the template from the DB.
id := getID(c)
if err := a.core.DeleteTemplate(id); err != nil {
return err
}
// Delete cached in-memory template.
a.manager.DeleteTpl(id)
return c.JSON(http.StatusOK, okResp{true})
}
// compileTemplate validates template fields.
func (a *App) validateTemplate(o models.Template) error {
if !strHasLen(o.Name, 1, stdInputMaxLen) {
return errors.New(a.i18n.T("campaigns.fieldInvalidName"))
}
if o.Type == models.TemplateTypeCampaign && !regexpTplTag.MatchString(o.Body) {
return echo.NewHTTPError(http.StatusBadRequest,
a.i18n.Ts("templates.placeholderHelp", "placeholder", tplTag))
}
if o.Type == models.TemplateTypeTx && strings.TrimSpace(o.Subject) == "" {
return echo.NewHTTPError(http.StatusBadRequest,
a.i18n.Ts("globals.messages.missingFields", "name", "subject"))
}
return nil
}
// previewTemplate renders the HTML preview of a template.
func (a *App) previewTemplate(tpl models.Template) ([]byte, error) {
var out []byteView on GitHub (pinned to 670c01717d)
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.
Example fix
// before
{"name": null, "body": "{{ template "content" . }}"}
// after
{"name": "Default campaign template", "body": "{{ template "content" . }}"} Defensive patterns
Strategy: validation
Validate before calling
function validateTemplateName(name) {
if (typeof name !== 'string' || name.trim().length === 0 || name.length > 200 /* stdInputMaxLen */) {
throw new Error('template name must be 1-200 characters');
}
} Type guard
function hasValidTemplateName(v: unknown): v is string {
return typeof v === 'string' && v.length >= 1 && v.length <= 200;
} Try / catch
try {
await api.createTemplate({ name, body });
} catch (e) {
if (e.message.includes('fieldInvalidName')) {
throw new Error('Template name is required (max ~200 chars)');
}
throw e;
} Prevention
- 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.
When it happens
Trigger: CreateTemplate or UpdateTemplate (POST/PUT /api/templates) with a name that is missing, empty, or longer than stdInputMaxLen characters.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- campaigns.fieldInvalidName
- campaigns.fieldInvalidSubject
- campaigns.fieldInvalidBody
- globals.messages.invalidFields
- campaigns.fieldInvalidFromEmail
AI-assisted analysis of knadh/listmonk@670c01717d (2026-09-01).
Data as JSON: /api/errors/5c7b9184ec8a51b2.
Report an issue: GitHub.