Billionmail/BillionMail · critical
Read database password failed: %v
Error message
Read database password failed: %v
What it means
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.
Source
Thrown at core/internal/service/database_initialization/database_initialization.go:20
import (
"billionmail-core/internal/consts"
"billionmail-core/internal/service/public"
"context"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"time"
)
var registeredHandlers = make([]func(), 0, 256)
// InitDatabase initializes the database configuration
func InitDatabase() (err error) {
dbPass, err := public.DockerEnv("DBPASS")
if err != nil {
return fmt.Errorf("Read database password failed: %v", err)
}
// Setting database configuration
err = gdb.SetConfig(gdb.Config{
"default": gdb.ConfigGroup{
gdb.ConfigNode{
// Debug: true,
Host: public.AbsPath(consts.POSTGRESQL_SOCK),
User: "billionmail",
Pass: dbPass,
Name: "billionmail",
Type: "pgsql",
Role: "master",
MaxOpenConnCount: 100,
},
},
})
View on GitHub (pinned to fc36c76c05)
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
Example fix
// before (docker-compose.yml)
services:
app:
# no env_file
// after
services:
app:
env_file:
- .env # contains DBPASS=... Defensive patterns
Strategy: validation
Validate before calling
pass, err := public.DockerEnv("DBPASS")
if err != nil || pass == "" {
return fmt.Errorf("DBPASS not available: %w", err)
} Try / catch
if err := database_initialization.InitDatabase(); err != nil {
if strings.Contains(err.Error(), "Read database password") {
log.Fatal("DBPASS env missing — check compose env_file")
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- Set database configuration failed: %v
- failed to create Docker client: %v
- failed to get all domains: %w
- fail to check domain: %w
- failed to get all emails: %w
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/3bfaba9e2d42b2d1.
Report an issue: GitHub.