{"record":{"id":"80e612414d3d6b41","repo":"vlucas/phpdotenv","slug":"at-least-one-environment-file-path-must-be-provide","errorCode":null,"errorMessage":"At least one environment file path must be provided.","messagePattern":"At least one environment file path must be provided\\.","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"src/Store/FileStore.php","lineNumber":59,"sourceCode":"     */\n    public function __construct(array $filePaths, bool $shortCircuit, ?string $fileEncoding = null)\n    {\n        $this->filePaths = $filePaths;\n        $this->shortCircuit = $shortCircuit;\n        $this->fileEncoding = $fileEncoding;\n    }\n\n    /**\n     * Read the content of the environment file(s).\n     *\n     * @throws \\Dotenv\\Exception\\InvalidEncodingException|\\Dotenv\\Exception\\InvalidPathException\n     *\n     * @return string\n     */\n    public function read()\n    {\n        if ($this->filePaths === []) {\n            throw new InvalidPathException('At least one environment file path must be provided.');\n        }\n\n        $contents = Reader::read($this->filePaths, $this->shortCircuit, $this->fileEncoding);\n\n        if (\\count($contents) > 0) {\n            return \\implode(\"\\n\", $contents);\n        }\n\n        throw new InvalidPathException(\n            \\sprintf('Unable to read any of the environment file(s) at [%s].', \\implode(', ', $this->filePaths))\n        );\n    }\n}\n","sourceCodeStart":41,"sourceCodeEnd":73,"githubUrl":"https://github.com/vlucas/phpdotenv/blob/416df702837983f8d5ff48c9c3fee4f5f57b980b/src/Store/FileStore.php#L41-L73","documentation":"FileStore::read() (src/Store/FileStore.php:59) throws Dotenv\\Exception\\InvalidPathException when the store was constructed with an empty list of file paths — i.e. zero candidate directories/names were registered, so no read is even attempted. This is a configuration error, distinct from [10] where paths exist but no file could be read. Note safeLoad() catches InvalidPathException too, so it also swallows this case and returns [].","triggerScenarios":"Dotenv::createImmutable([])->load() or Dotenv::create($repo, [])->load(); a StoreBuilder built with createWithDefaultName() but no addPath() call; paths computed dynamically from glob()/scandir()/config that returned an empty array before create() was called.","commonSituations":"Config-driven env directories ('env_paths' key empty in a bundle config); glob() matching nothing because the cwd differs from the project root; refactoring that moved the path list construction and silently dropped it.","solutions":["Pass at least one directory: Dotenv::createImmutable(__DIR__)->load() (default name '.env' is appended).","Guard dynamic lists: $paths = $computed ?: [__DIR__];","If the env file is genuinely optional, call safeLoad() instead of load() — it suppresses this exception.","Log count($paths) during boot to catch the misconfiguration early."],"exampleFix":"// before\n$dirs = glob(__DIR__.'/modules/*/.env', GLOB_ONLYDIR) ?: [];\nDotenv::createImmutable(array_map('dirname', $dirs))->load(); // empty on fresh clone -> throws\n\n// after\n$dirs = glob(__DIR__.'/modules/*/.env', GLOB_ONLYDIR) ?: [];\nDotenv::createImmutable(array_map('dirname', $dirs) ?: [__DIR__])->safeLoad();","handlingStrategy":"validation","validationCode":"// Never hand Dotenv an empty path list:\n$paths = array_filter(\n    array_map('strval', (array) ($config['env_dirs'] ?? [])),\n    static fn (string $p) => trim($p, '/ ') !== ''\n);\nif ($paths === []) {\n    $paths = [dirname(__DIR__)]; // sane fallback: project root\n}\nDotenv::createImmutable($paths)->safeLoad();","typeGuard":"function hasEnvPaths(array $paths): bool\n{\n    return count(array_filter($paths, 'is_string')) > 0;\n}","tryCatchPattern":null,"preventionTips":["Log the resolved path list during bootstrap so an empty list is visible immediately.","Treat 'no directories configured' as a boot-time config error, not a runtime surprise.","Remember safeLoad() also swallows this exception — use load() in environments where you want to be warned."],"tags":["dotenv","env-file","path","configuration","php"],"backgroundTag":"env-file-path-missing","analyzedSha":"416df702837983f8d5ff48c9c3fee4f5f57b980b","analyzedAt":"2026-08-21T01:19:52.946Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}