{"record":{"id":"f43307f8d31e3426","repo":"Billionmail/BillionMail","slug":"failed-to-create-email-w","errorCode":null,"errorMessage":"Failed to create email: %w","messagePattern":"Failed to create email: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/internal/service/mail_boxes/mail_boxes.go","lineNumber":367,"sourceCode":"\t\t\t\tmb := mbs[i]\n\t\t\t\tsem <- struct{}{}\n\t\t\t\tgo func(mb v1.Mailbox) {\n\t\t\t\t\tdefer func() { <-sem }()\n\t\t\t\t\t_ = ensureMaildirAndQuotaFile(context.Background(), &mb)\n\t\t\t\t}(mb)\n\t\t\t}\n\n\t\t\tfor i := 0; i < cap(sem); i++ {\n\t\t\t\tsem <- struct{}{}\n\t\t\t}\n\t\t}(mailboxes)\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\n\t\treturn nil, fmt.Errorf(\"Failed to create email: %w\", err)\n\t}\n\n\tif len(emailList) == 0 {\n\t\treturn nil, fmt.Errorf(\"Failed to create any mailbox\")\n\t}\n\n\treturn emailList, nil\n}\n\n// AddImport\nfunc AddImport(ctx context.Context, mailbox *v1.Mailbox) (err error) {\n\n\tif mailbox.PasswordEncode != \"\" {\n\n\t\tif mailbox.Password == \"\" {\n\t\t\tmailbox.Password, err = PasswdDecode(ctx, mailbox.PasswordEncode)\n\t\t\tif err != nil {\n\t\t\t\terr = fmt.Errorf(\"Decode password failed: %w\", err)","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/mail_boxes/mail_boxes.go#L349-L385","documentation":"Top-level wrapper in BatchAdd: after the transaction closure runs, any error it returned is re-wrapped as 'Failed to create email: %w'. It indicates that the batch mailbox creation transaction did not complete — the real cause is always nested inside. If err is nil but nothing was created, error 325 is thrown instead.","triggerScenarios":"Any failure inside the BatchAdd transaction (e.g. error 323 batch insert failure) surfacing at the BatchAddMailbox call boundary.","commonSituations":"Bulk mailbox provisioning failing because of database errors, constraint conflicts, or transaction aborts.","solutions":["Unwrap the error to find the root cause (look for 'Batch insert mailbox failed' or similar)","Fix the underlying database/transaction issue identified by the wrapped error","Retry the batch creation after resolving the cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"created, err := BatchAddMailbox(...)\nif err != nil {\n    var root = err\n    for errors.Unwrap(root) != nil { root = errors.Unwrap(root) }\n    log.Printf(\"batch create failed, root cause: %v\", root)\n}","preventionTips":["Always unwrap to the root cause before acting on this error","Fix DB-level issues before retrying bulk creations","Log the full error chain for diagnosis"],"tags":["go","database","transaction","batch"],"backgroundTag":"database-insert-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-15T02:17:10.978Z"}