{"record":{"id":"faf841a9829c8119","repo":"knadh/listmonk","slug":"campaigns-fieldinvalidname","errorCode":null,"errorMessage":"campaigns.fieldInvalidName","messagePattern":"campaigns\\.fieldInvalidName","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/campaigns.go","lineNumber":690,"sourceCode":"\t\ta.log.Printf(\"error rendering message: %v\", err)\n\t\treturn echo.NewHTTPError(http.StatusNotFound, a.i18n.Ts(\"templates.errorRendering\", \"error\", err.Error()))\n\t}\n\n\treturn a.manager.PushCampaignMessage(msg)\n}\n\n// validateCampaignFields validates incoming campaign field values.\nfunc (a *App) validateCampaignFields(c campReq) (campReq, error) {\n\tif c.FromEmail == \"\" {\n\t\tc.FromEmail = a.cfg.FromEmail\n\t} else if !reFromAddress.Match([]byte(c.FromEmail)) {\n\t\tif _, err := a.importer.SanitizeEmail(c.FromEmail); err != nil {\n\t\t\treturn c, errors.New(a.i18n.T(\"campaigns.fieldInvalidFromEmail\"))\n\t\t}\n\t}\n\n\tif !strHasLen(c.Name, 1, stdInputMaxLen) {\n\t\treturn c, errors.New(a.i18n.T(\"campaigns.fieldInvalidName\"))\n\t}\n\n\t// Larger char limit for subject as it can contain {{ go templating }} logic.\n\tif !strHasLen(c.Subject, 1, 5000) {\n\t\treturn c, errors.New(a.i18n.T(\"campaigns.fieldInvalidSubject\"))\n\t}\n\n\t// If no content-type is specified, default to richtext.\n\tif c.ContentType != models.CampaignContentTypeRichtext &&\n\t\tc.ContentType != models.CampaignContentTypeHTML &&\n\t\tc.ContentType != models.CampaignContentTypePlain &&\n\t\tc.ContentType != models.CampaignContentTypeVisual &&\n\t\tc.ContentType != models.CampaignContentTypeMarkdown {\n\t\tc.ContentType = models.CampaignContentTypeRichtext\n\t}\n\n\tif c.ContentType != models.CampaignContentTypeVisual {\n\t\tc.BodySource.Valid = false","sourceCodeStart":672,"sourceCodeEnd":708,"githubUrl":"https://github.com/knadh/listmonk/blob/670c01717d48647093335cc23a6be6f4b79c3b6b/cmd/campaigns.go#L672-L708","documentation":"validateCampaignFields enforces strHasLen(c.Name, 1, stdInputMaxLen): the campaign name must be between 1 and stdInputMaxLen characters. The error is returned for empty names or names exceeding the standard input limit.","triggerScenarios":"CreateCampaign, UpdateCampaign, or TestCampaign called with a JSON body where 'name' is absent, empty string, whitespace-only (not trimmed by validator), or longer than stdInputMaxLen characters.","commonSituations":"Automated API scripts that forget the name field, bulk import payloads with null/empty names, or names built from templated strings that exceed the length cap.","solutions":["Provide a non-empty name within stdInputMaxLen characters in the request body.","Trim the name and shorten it programmatically before calling the API.","In UI clients, enforce a maxlength input attribute and require the field before submit."],"exampleFix":"// before\n{\"name\": \"\"}\n// after\n{\"name\": \"August Newsletter 2026\"}","handlingStrategy":"validation","validationCode":"function validateCampaignName(name) {\n  if (typeof name !== 'string' || name.trim().length === 0 || name.length > 200 /* stdInputMaxLen */) {\n    throw new Error('campaign name must be 1-200 characters');\n  }\n}","typeGuard":"function hasValidName(v: unknown): v is string {\n  return typeof v === 'string' && v.length >= 1 && v.length <= 200;\n}","tryCatchPattern":"try {\n  await api.createCampaign({ name, ...rest });\n} catch (e) {\n  if (e.message.includes('fieldInvalidName')) {\n    throw new Error('Campaign name is required (max ~200 chars)');\n  }\n  throw e;\n}","preventionTips":["Make name a required, non-blank field in any UI or automation that creates campaigns.","Truncate auto-generated names to the length cap.","Reject whitespace-only names client-side."],"tags":["validation","campaign","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"}