{"record":{"id":"4eb5773cb5b12fe2","repo":"symfony/thanks","slug":"could-not-find-your-composer-json-file","errorCode":null,"errorMessage":"Could not find your composer.json file!","messagePattern":"Could not find your composer\\.json file!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/GitHubClient.php","lineNumber":204,"sourceCode":"                    continue;\n                }\n\n                foreach ($error['path'] as $path) {\n                    $failures += [$path => $error['message']];\n                    unset($result['data'][$path]);\n                }\n            }\n        }\n\n        return isset($result['data']) ? $result['data'] : [];\n    }\n\n    private function getDirectlyRequiredPackageNames(): array\n    {\n        $file = new JsonFile(Factory::getComposerFile(), null, $this->io);\n\n        if (!$file->exists()) {\n            throw new \\Exception('Could not find your composer.json file!');\n        }\n\n        $data = $file->read() + ['require' => [], 'require-dev' => []];\n        $data = array_keys($data['require'] + $data['require-dev']);\n\n        return array_combine($data, $data);\n    }\n\n    private function processChunks(array $urls, bool $withFundingLinks, ?array &$failures = null): array\n    {\n        $i = 0;\n        $template = $withFundingLinks\n            ? '_%d: repository(owner:\"%s\",name:\"%s\"){id,viewerHasStarred,fundingLinks{platform,url}}'.\"\\n\"\n            : '_%d: repository(owner:\"%s\",name:\"%s\"){id,viewerHasStarred}'.\"\\n\";\n        $graphql = '';\n\n        $aliases = [];\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/symfony/thanks/blob/f455cc9ba4e0c61dcc18ea7e52bd725ee661aa64/src/GitHubClient.php#L186-L222","documentation":"getDirectlyRequiredPackageNames() resolves composer.json via Factory::getComposerFile() and throws a plain \\Exception when that file does not exist. The library reads require/require-dev package names from composer.json (to filter which repos to query via getRepositories), so without the file it cannot proceed. This is a fail-fast guard against running outside a Composer project.","triggerScenarios":"Calling getRepositories() (which calls getDirectlyRequiredPackageNames()) from a working directory where composer.json does not exist at the path Factory::getComposerFile() resolves to — i.e. cwd is not a Composer project root.","commonSituations":"Running the composer command from a subdirectory or a directory with no composer.json, invoking the library programmatically outside a project, or a project that only has composer.lock (no composer.json).","solutions":["Run the command from the directory containing your composer.json (project root)","Create a composer.json in the current directory if it genuinely should be a project (composer init)","When using the library programmatically, chdir() to the project root or configure the Composer factory so Factory::getComposerFile() points at a real composer.json"],"exampleFix":"// before (wrong cwd)\n$ cd subdirectory && composer funding   # Exception: Could not find your composer.json file!\n// after\n$ cd /path/to/project && composer funding","handlingStrategy":"validation","validationCode":"$composerJson = getcwd() . '/composer.json';\nif (!is_file($composerJson)) {\n    throw new RuntimeException(\"Run from your project root: {$composerJson} not found\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $repos = $client->getRepositories($urls);\n} catch (\\Exception $e) {\n    if ($e->getMessage() === 'Could not find your composer.json file!') {\n        fwrite(STDERR, 'Not in a Composer project: cd to your project root and retry.');\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Run composer commands from the project root, not subdirectories","Verify composer.json exists alongside composer.lock before scripting library calls","When calling the API programmatically, set cwd or the COMPOSER env var to the project's composer.json path","Ensure composer.json is committed/present, not just composer.lock"],"tags":["composer","config-file","working-directory","file-not-found"],"backgroundTag":"config-file-not-found","analyzedSha":"f455cc9ba4e0c61dcc18ea7e52bd725ee661aa64","analyzedAt":"2026-09-13T17:43:01.449Z","contentChangedAt":"2026-09-13T17:43:01.449Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}