{"record":{"id":"e9533e7df84dbd39","repo":"phalcon/cphalcon","slug":"configuration-file-filename-cannot-be-loaded-e9533e","errorCode":null,"errorMessage":"Configuration file {fileName} cannot be loaded","messagePattern":"Configuration file (.+?) cannot be loaded","errorType":"exception","errorClass":"Phalcon\\Config\\Exceptions\\CannotLoadConfigFile","httpStatus":null,"severity":"error","filePath":"phalcon/Config/Adapter/Json.zep","lineNumber":54,"sourceCode":" *```\n */\nclass Json extends Config\n{\n    use FileTrait;\n\n    /**\n     * Phalcon\\Config\\Adapter\\Json constructor\n     *\n     * @throws CannotLoadConfigFile\n     */\n    public function __construct( string filePath)\n    {\n        var content;\n\n        let content = this->phpFileGetContents(filePath);\n\n        if unlikely content === false {\n            throw new CannotLoadConfigFile(basename(filePath));\n        }\n\n        parent::__construct(\n            (new Decode())->__invoke(content, true)\n        );\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":62,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Config/Adapter/Json.zep#L36-L62","documentation":"Config\\Adapter\\Json reads the file with file_get_contents(); if that returns false (missing or unreadable file), CannotLoadConfigFile is thrown with the basename. Note that invalid JSON content is a separate failure — it surfaces later in the Json decoder, not from this check.","triggerScenarios":"new Json('/missing/config.json'); a relative path resolved from a different working directory; a file present but not readable by the PHP process.","commonSituations":"Deploying without the .json config file; config generated by a build step that did not run; path typos after moving the project root.","solutions":["Verify the file exists and is readable before loading","Use absolute paths built from __DIR__","If config is build-generated, fail the build when the file is missing instead of at runtime"],"exampleFix":"// before\n$config = new \\Phalcon\\Config\\Adapter\\Json('config/app.json');\n\n// after\n$path = dirname(__DIR__) . '/config/app.json';\nif (!is_readable($path)) {\n    throw new RuntimeException('Missing config file: ' . $path);\n}\n$config = new \\Phalcon\\Config\\Adapter\\Json($path);","handlingStrategy":"validation","validationCode":"$path = dirname(__DIR__) . '/config/app.json';\nif (!is_file($path) || !is_readable($path)) {\n    throw new RuntimeException('Config file missing or unreadable: ' . $path);\n}\n$config = new \\Phalcon\\Config\\Adapter\\Json($path);","typeGuard":null,"tryCatchPattern":"try {\n    $config = new \\Phalcon\\Config\\Adapter\\Json($path);\n} catch (\\Phalcon\\Config\\Adapter\\Json\\Exception\\CannotLoadConfigFile $e) {\n    // Unreadable file (distinct from invalid JSON, which fails in the decoder)\n    throw new RuntimeException('Failed to read json config: ' . $path, 0, $e);\n}","preventionTips":["Verify existence/readability before loading","If a build step generates the JSON config, fail the build when the output file is missing","Use absolute paths from __DIR__ in CLI entry points"],"tags":["phalcon","config","json","file-path","configuration"],"backgroundTag":"config-file-load-failed","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}