Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument 2 passed to Composer\Pcre\Preg::isMatch() must be of the type string, null given #10888

Closed
bartlangelaan opened this issue Jun 20, 2022 · 3 comments
Labels
Milestone

Comments

@bartlangelaan
Copy link

bartlangelaan commented Jun 20, 2022

In the CI (not on my machine) during a composer create-project, this error occurs:

    Exception trace:
      at /app/.global/composer/composer/vendor/composer/pcre/src/Preg.php:233
     Composer\Pcre\Preg::isMatch() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Downloader/GitDownloader.php:475
     Composer\Downloader\GitDownloader->updateToCommit() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Downloader/GitDownloader.php:138
     Composer\Downloader\GitDownloader->doInstall() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Downloader/VcsDownloader.php:137
     Composer\Downloader\VcsDownloader->install() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Downloader/DownloadManager.php:279
     Composer\Downloader\DownloadManager->install() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Installer/LibraryInstaller.php:282
     Composer\Installer\LibraryInstaller->installCode() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Installer/LibraryInstaller.php:155
     Composer\Installer\LibraryInstaller->install() at /app/.global/composer/composer/vendor/composer/composer/src/Composer/Installer/InstallationManager.php:528

I think this is related to composer/pcre@2e56743, #10662 and 0708eb4.

Looking at the code, I could see how this could possibly go wrong:

$branches = null;
if (0 === $this->process->execute('git branch -r', $output, $path)) {
$branches = $output;
}

// try to checkout branch by name and then reset it so it's on the proper branch name
if (Preg::isMatch('{^[a-f0-9]{40}$}', $reference)) {
// add 'v' in front of the branch if it was stripped when generating the pretty name
if (!Preg::isMatch('{^\s+composer/'.preg_quote($branch).'$}m', $branches) && Preg::isMatch('{^\s+composer/v'.preg_quote($branch).'$}m', $branches)) {
$branch = 'v' . $branch;
}

So, it seems like the $branches var is used while it is null.
However, it's hard for me to check if adding a && $branches to the outer if-statement is enough to fix this issue, because this error only happens in the CI for me. But it seems like a good thing to do anyway.

@Seldaek Seldaek added this to the 2.3 milestone Jun 21, 2022
@Seldaek Seldaek added the Bug label Jun 21, 2022
@Seldaek
Copy link
Member

Seldaek commented Jun 22, 2022

Do you not have git installed on CI, or why is it failing to execute git branch -r? Or maybe you cache vendor dir but not the .git dirs within?

I mean we need to fix this regardless, but I am curious how you reach this code path.

@Seldaek Seldaek modified the milestones: 2.3, 2.2 Jun 22, 2022
@brunoborghi
Copy link

brunoborghi commented Sep 18, 2022

Interesting...

@Seldaek, on CI after run composer install, before generating autoload files, this error occurs:

[TypeError] Argument 2 passed to Composer\Pcre\Preg::matchAll() must be of the type str ing, null given, called in phar:///.../composer.phar/vendor/composer/class-map-generator/src/PhpFil eParser.php on line 55

Trace:

Exception trace: at phar:///.../composer.phar/vendor/composer/pcre/src/Preg.php:67 Composer\Pcre\Preg::matchAll() at phar:///.../composer.phar/vendor/composer/class-map-generator/src/PhpFileParser.php:55 Composer\ClassMapGenerator\PhpFileParser::findClasses() at phar:///.../composer.phar/vendor/composer/class-map-generator/src/ClassMapGenerator.php:176 Composer\ClassMapGenerator\ClassMapGenerator->scanPaths() at phar:///.../composer.phar/src/Composer/Autoload/AutoloadGenerator.php:314 Composer\Autoload\AutoloadGenerator->dump() at phar:///.../composer.phar/src/Composer/Installer.php:343 Composer\Installer->run() at phar:///.../composer.phar/src/Composer/Command/UpdateCommand.php:240 Composer\Command\UpdateCommand->execute() at phar:///.../composer.phar/vendor/symfony/console/Command/Command.php:298 Symfony\Component\Console\Command\Command->run() at phar:///.../composer.phar/vendor/symfony/console/Application.php:1028 Symfony\Component\Console\Application->doRunCommand() at phar:///.../composer.phar/vendor/symfony/console/Application.php:299 Symfony\Component\Console\Application->doRun() at phar:///.../composer.phar/src/Composer/Console/Application.php:370 Composer\Console\Application->doRun() at phar:///.../composer.phar/vendor/symfony/console/Application.php:171 Symfony\Component\Console\Application->run() at phar:///.../composer.phar/src/Composer/Console/Application.php:138 Composer\Console\Application->run() at phar:///.../composer.phar/bin/composer:88 require() at /.../composer.phar:29

I'm using version 2.4.2. Could it have something to do with this error?
On my computer it works normally.

@Seldaek
Copy link
Member

Seldaek commented Oct 12, 2022

@brunoborghi that is an unrelated issue, but I wonder how that is possible at all. The $contents / arg #2 here https://github.com/composer/class-map-generator/blob/main/src/PhpFileParser.php#L55 should always be a string as php_strip_whitespace can only return a string, and as per https://3v4l.org/r4kMa it seems to be the case even for non-existent paths.

It doesn't make sense to me how it'd be null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants