{"record":{"id":"083ad47acf61fdb4","repo":"Billionmail/BillionMail","slug":"environment-file-not-found","errorCode":null,"errorMessage":"environment file not found: ","messagePattern":"environment file not found: ","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/public/common.go","lineNumber":2407,"sourceCode":"\t\tg.Log().Error(context.Background(), \"ReloadFirewall error: \", err, \" \", s)\n\t\treturn\n\t}\n\n\treturn\n}\n\n// DockerApiFromCtx Get Docker API from context\nfunc DockerApiFromCtx(ctx context.Context) *docker.DockerAPI {\n\treturn ctx.Value(consts.DEFAULT_DOCKER_CLIENT_CTX_KEY).(*docker.DockerAPI)\n}\n\n// DockerEnv get Docker Environment Configuration\nfunc DockerEnv(envName string) (envVal string, err error) {\n\t// Read environment from ../.env\n\tenvFile := AbsPath(consts.DEFAULT_DOCKER_ENV_FILE)\n\n\tif !FileExists(envFile) {\n\t\terr = errors.New(\"environment file not found: \" + envFile)\n\t\treturn\n\t}\n\n\t// Read each lines\n\terr = ReadEach(envFile, func(row string, cnt int) bool {\n\t\t// Trim whitespace\n\t\trow = strings.TrimSpace(row)\n\n\t\t// Ingore empty line\n\t\tif row == \"\" {\n\t\t\treturn true\n\t\t}\n\n\t\t// Ingore comment line\n\t\tif strings.HasPrefix(row, \"#\") {\n\t\t\treturn true\n\t\t}\n","sourceCodeStart":2389,"sourceCodeEnd":2425,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/public/common.go#L2389-L2425","documentation":"DockerEnv in core/internal/service/public/common.go reads an environment variable from the Docker .env file located at AbsPath(consts.DEFAULT_DOCKER_ENV_FILE). If that file does not exist on disk it returns \"environment file not found: <path>\". This means the deployment's .env file is missing from the expected location, not that the specific env var is missing.","triggerScenarios":"Calling DockerEnv(\"SOME_VAR\") when ../.env (relative to the binary, via AbsPath) was never created, was deleted, or the process is running from a different working directory so AbsPath resolves to a wrong/nonexistent path.","commonSituations":"Running the app outside the standard Docker Compose layout (bare-metal dev run), fresh checkout without copying .env.example to .env, container started without the .env volume mounted, or changed install directory.","solutions":["Create the .env file at the resolved path (copy .env.example to .env and fill values).","Verify the working directory: print the path from the error message and check it exists with ls.","If running outside Docker, mount or symlink the .env file into the expected location.","Alternatively set the variable in the actual OS environment and adjust code to prefer os.LookupEnv with file fallback."],"exampleFix":"// before\nval, err := public.DockerEnv(\"SMTP_HOST\") // environment file not found: /opt/app/.env\n// after\ncp .env.example /opt/app/.env  # then\nval, err := public.DockerEnv(\"SMTP_HOST\")","handlingStrategy":"validation","validationCode":"envFile := public.AbsPath(consts.DEFAULT_DOCKER_ENV_FILE)\nif !public.FileExists(envFile) {\n    return fmt.Errorf(\".env missing at %s: copy .env.example first\", envFile)\n}\nval, err := public.DockerEnv(\"SOME_VAR\")","typeGuard":null,"tryCatchPattern":"val, err := public.DockerEnv(name)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"environment file not found:\") {\n        log.Printf(\"%v — falling back to OS env\", err)\n        val = os.Getenv(name)\n        return val, nil\n    }\n    return err\n}","preventionTips":["Ship a startup check that verifies .env exists and fails fast with instructions","Document that the app must run from its deploy directory so AbsPath resolves correctly","Mount .env into containers explicitly in docker-compose.yml","Add .env existence to health checks"],"tags":["configuration","env-file","docker","go"],"backgroundTag":"missing-env-file","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}