{"record":{"id":"c5e068cb36cf10aa","repo":"Billionmail/BillionMail","slug":"you-cannot-create-more-than-5000-batches","errorCode":null,"errorMessage":"You cannot create more than 5000 batches","messagePattern":"You cannot create more than 5000 batches","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/controller/mail_boxes/mail_boxes_v1_batch_add_mailbox.go","lineNumber":18,"sourceCode":"package mail_boxes\n\nimport (\n\t\"billionmail-core/internal/consts\"\n\t\"billionmail-core/internal/service/public\"\n\t\"context\"\n\t\"fmt\"\n\n\t\"billionmail-core/api/mail_boxes/v1\"\n\t\"billionmail-core/internal/service/mail_boxes\"\n)\n\nfunc (c *ControllerV1) BatchAddMailbox(ctx context.Context, req *v1.BatchAddMailboxReq) (res *v1.BatchAddMailboxRes, err error) {\n\n\tres = &v1.BatchAddMailboxRes{}\n\n\tif req.Count > 5000 {\n\t\treturn nil, fmt.Errorf(\"You cannot create more than 5000 batches\")\n\t}\n\n\tcreatedEmails, err := mail_boxes.BatchAdd(ctx, req.Domain, req.Quota, req.Count, req.Prefix, req.QuotaActive)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tsuccessMsg := fmt.Sprintf(\"%d email accounts were successfully created\", len(createdEmails))\n\n\t_ = public.WriteLog(ctx, public.LogParams{\n\t\tType: consts.LOGTYPE.Mailboxes,\n\t\tLog:  \"Batch email creation was successful\",\n\t\tData: req,\n\t})\n\tres.SetSuccess(successMsg)\n\tres.Data = createdEmails\n\treturn res, nil\n}","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/controller/mail_boxes/mail_boxes_v1_batch_add_mailbox.go#L1-L36","documentation":"BatchAddMailbox enforces a hard cap: req.Count may not exceed 5000 mailboxes per call. The guard returns before invoking mail_boxes.BatchAdd. It exists to protect the DB and Dovecot provisioning from unbounded bulk creation in one request.","triggerScenarios":"Calling BatchAddMailbox with a count body field greater than 5000, e.g. {\"count\": 10000}.","commonSituations":"Bulk-provisioning a large organization in one request; a frontend mis-sending a default or sentinel value; automated scripts computing count from a full employee list.","solutions":["Split the request into chunks of at most 5000 and call BatchAddMailbox repeatedly.","Lower req.Count to the actually needed number.","Increase the limit in the controller only if provisioning infrastructure can handle it (requires code change)."],"exampleFix":"// before\n{\"domain\":\"example.com\",\"count\":12000}\n// after\n// 3 calls with count 5000, 5000, 2000","handlingStrategy":"validation","validationCode":"const MAX_BATCH = 5000\nif (!Number.isInteger(count) || count < 1 || count > MAX_BATCH) {\n  throw new Error(`count must be between 1 and ${MAX_BATCH}`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.batchAddMailbox({domain, count})\n} catch (e) {\n  if (String(e.message).includes('more than 5000')) {\n    for (const chunk of chunkArray(requests, 5000)) await api.batchAddMailbox({domain, count: chunk})\n  } else throw e\n}","preventionTips":["Clamp batch size to 5000 (or less) in client code.","Chunk very large provisioning jobs instead of one giant request.","Document the limit wherever the API client is generated."],"tags":["validation","limits","mailboxes"],"backgroundTag":"request-limit-exceeded","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}