{"record":{"id":"c551824dabbb2d57","repo":"Billionmail/BillionMail","slug":"hostworkdir-not-set","errorCode":null,"errorMessage":"HostWorkDir not set","messagePattern":"HostWorkDir not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/mail_boxes/init_quota_plugin.go","lineNumber":27,"sourceCode":"\t\"fmt\"\n\t\"github.com/gogf/gf/v2/frame/g\"\n\t\"github.com/gogf/gf/v2/os/gfile\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"regexp\"\n\t\"strings\"\n\t\"time\"\n)\n\n// Initialize quota plugin. If not installed, install it first.\n// Modify dovecot.conf, 20-pop3.conf, and 90-quota.conf.\n// Rebuild dovecot-sql.conf.ext\n// Check all mailboxes and add the maildirsize file (make sure the file permissions are correct)\n\nfunc InitQuotaPluginAndUpdateUsedSpace(ctx context.Context) error {\n\tif public.HostWorkDir == \"\" {\n\t\treturn errors.New(\"HostWorkDir not set\")\n\t}\n\n\tmarkPath := public.AbsPath(\"../core/data/quota_init_done.mark\")\n\n\tif gfile.Exists(markPath) {\n\t\treturn nil\n\t}\n\n\tconfRoot := public.AbsPath(\"../conf/dovecot\")\n\n\tif _, err := os.Stat(confRoot); os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"dovecot conf dir not found: %s\", confRoot)\n\t}\n\n\t// 1. Modify dovecot.conf\n\tif err := ensureDovecotConf(confRoot); err != nil {\n\t\treturn err\n\t}","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/mail_boxes/init_quota_plugin.go#L9-L45","documentation":"InitQuotaPluginAndUpdateUsedSpace configures the Dovecot quota plugin and needs the host working directory to locate on-disk config and maildir paths. If public.HostWorkDir is empty (never initialized at startup), it refuses to proceed with this sentinel error.","triggerScenarios":"Calling InitQuotaPluginAndUpdateUsedSpace before application bootstrap populated public.HostWorkDir, or the init code that sets HostWorkDir was skipped/misordered (e.g. running the function from a standalone script or test).","commonSituations":"Deployment where the work-dir env/config is missing so bootstrap leaves HostWorkDir empty; calling the init routine from a cron job with a minimal entrypoint that skips normal app init; unit tests invoking the function without fixtures.","solutions":["Ensure the application bootstrap sets public.HostWorkDir before calling this function","Verify the work-dir config/env var is present in the deployment and parsed at startup","In scripts/tests, set public.HostWorkDir manually to the repo/deployment root before invoking","Run the init via the normal application startup path rather than a bare entrypoint"],"exampleFix":"// before\nerr := mail_boxes.InitQuotaPluginAndUpdateUsedSpace(ctx)\n// after\nif public.HostWorkDir == \"\" {\n\tpublic.HostWorkDir = os.Getenv(\"BM_WORK_DIR\") // or standard bootstrap\n}\nif err := mail_boxes.InitQuotaPluginAndUpdateUsedSpace(ctx); err != nil {\n\tg.Log().Error(ctx, \"quota init failed\", err)\n}","handlingStrategy":"validation","validationCode":"if public.HostWorkDir == \"\" {\n\tpublic.HostWorkDir = os.Getenv(\"BM_WORK_DIR\")\n}\nif public.HostWorkDir == \"\" {\n\treturn errors.New(\"HostWorkDir not set; configure work dir before quota init\")\n}","typeGuard":null,"tryCatchPattern":"if err := mail_boxes.InitQuotaPluginAndUpdateUsedSpace(ctx); err != nil && err.Error() == \"HostWorkDir not set\" {\n\tlog.Printf(\"bootstrap incomplete: set HostWorkDir before quota init\")\n}","preventionTips":["Initialize public.HostWorkDir in application bootstrap before any service init","Require the work-dir env var at container startup (fail fast)","Never invoke service init routines from scripts that skip bootstrap","Add a startup assertion that HostWorkDir is non-empty"],"tags":["configuration","env","dovecot","quota"],"backgroundTag":"missing-env-var","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"}