{"record":{"id":"3bfaba9e2d42b2d1","repo":"Billionmail/BillionMail","slug":"read-database-password-failed-v","errorCode":null,"errorMessage":"Read database password failed: %v","messagePattern":"Read database password failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/internal/service/database_initialization/database_initialization.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"billionmail-core/internal/consts\"\n\t\"billionmail-core/internal/service/public\"\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/gogf/gf/v2/database/gdb\"\n\t\"github.com/gogf/gf/v2/frame/g\"\n\t\"time\"\n)\n\nvar registeredHandlers = make([]func(), 0, 256)\n\n// InitDatabase initializes the database configuration\nfunc InitDatabase() (err error) {\n\tdbPass, err := public.DockerEnv(\"DBPASS\")\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Read database password failed: %v\", err)\n\t}\n\n\t// Setting database configuration\n\terr = gdb.SetConfig(gdb.Config{\n\t\t\"default\": gdb.ConfigGroup{\n\t\t\tgdb.ConfigNode{\n\t\t\t\t// Debug: true,\n\t\t\t\tHost:             public.AbsPath(consts.POSTGRESQL_SOCK),\n\t\t\t\tUser:             \"billionmail\",\n\t\t\t\tPass:             dbPass,\n\t\t\t\tName:             \"billionmail\",\n\t\t\t\tType:             \"pgsql\",\n\t\t\t\tRole:             \"master\",\n\t\t\t\tMaxOpenConnCount: 100,\n\t\t\t},\n\t\t},\n\t})\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/database_initialization/database_initialization.go#L2-L38","documentation":"InitDatabase reads the PostgreSQL password from the Docker environment via public.DockerEnv(\"DBPASS\") before configuring GoFrame's DB group. If that env lookup fails (file missing, unreadable, DBPASS absent), initialization aborts early with this wrapped error.","triggerScenarios":"Starting the app outside the expected Docker Compose environment where the env file holding DBPASS doesn't exist; DBPASS variable not defined in the .env/compose environment; permission error reading the env source.","commonSituations":"Running the binary locally without docker-compose; renamed or removed DBPASS variable; docker env file path changed between deployments; container restarted without the env_file entry.","solutions":["Ensure the container/instance has DBPASS exported (check docker-compose env_file or .env)","Verify the Docker environment file exists and is readable by the process (public.DockerEnv source path)","Set DBPASS manually in the runtime environment as a workaround: DBPASS=secret ./app","Check the wrapped cause (%v) to distinguish missing-var from read-permission errors"],"exampleFix":"// before (docker-compose.yml)\nservices:\n  app:\n    # no env_file\n// after\nservices:\n  app:\n    env_file:\n      - .env  # contains DBPASS=...","handlingStrategy":"validation","validationCode":"pass, err := public.DockerEnv(\"DBPASS\")\nif err != nil || pass == \"\" {\n    return fmt.Errorf(\"DBPASS not available: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := database_initialization.InitDatabase(); err != nil {\n    if strings.Contains(err.Error(), \"Read database password\") {\n        log.Fatal(\"DBPASS env missing — check compose env_file\")\n    }\n}","preventionTips":["Define DBPASS in every deployment environment","Keep the env file mounted and readable in containers","Fail fast at container start with a clear message","Document required env vars in deployment docs"],"tags":["database","configuration","environment"],"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"}