symfony/thanks · error · Exception

Could not find your composer.json file!

Error message

Could not find your composer.json file!

What it means

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.

Solutions

  1. Run the command from the directory containing your composer.json (project root)
  2. Create a composer.json in the current directory if it genuinely should be a project (composer init)
  3. When using the library programmatically, chdir() to the project root or configure the Composer factory so Factory::getComposerFile() points at a real composer.json

Example fix

// before (wrong cwd)
$ cd subdirectory && composer funding   # Exception: Could not find your composer.json file!
// after
$ cd /path/to/project && composer funding
Defensive patterns

Strategy: validation

Validate before calling

$composerJson = getcwd() . '/composer.json';
if (!is_file($composerJson)) {
    throw new RuntimeException("Run from your project root: {$composerJson} not found");
}

Try / catch

try {
    $repos = $client->getRepositories($urls);
} catch (\Exception $e) {
    if ($e->getMessage() === 'Could not find your composer.json file!') {
        fwrite(STDERR, 'Not in a Composer project: cd to your project root and retry.');
        exit(1);
    }
    throw $e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.


AI-assisted analysis of symfony/thanks@f455cc9ba4 (2026-09-13). Data as JSON: /api/errors/4eb5773cb5b12fe2. Report an issue: GitHub.

Appendix: source

Thrown at src/GitHubClient.php:204

                    continue;
                }

                foreach ($error['path'] as $path) {
                    $failures += [$path => $error['message']];
                    unset($result['data'][$path]);
                }
            }
        }

        return isset($result['data']) ? $result['data'] : [];
    }

    private function getDirectlyRequiredPackageNames(): array
    {
        $file = new JsonFile(Factory::getComposerFile(), null, $this->io);

        if (!$file->exists()) {
            throw new \Exception('Could not find your composer.json file!');
        }

        $data = $file->read() + ['require' => [], 'require-dev' => []];
        $data = array_keys($data['require'] + $data['require-dev']);

        return array_combine($data, $data);
    }

    private function processChunks(array $urls, bool $withFundingLinks, ?array &$failures = null): array
    {
        $i = 0;
        $template = $withFundingLinks
            ? '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred,fundingLinks{platform,url}}'."\n"
            : '_%d: repository(owner:"%s",name:"%s"){id,viewerHasStarred}'."\n";
        $graphql = '';

        $aliases = [];

View on GitHub (pinned to f455cc9ba4)