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

[2.2.0-RC1] AutoloadGenerator.php crashes when overriding a file using autoload.files + autoload.exclude-from-classmap #10344

Closed
ruudk opened this issue Dec 8, 2021 · 2 comments
Labels
Milestone

Comments

@ruudk
Copy link
Contributor

ruudk commented Dec 8, 2021

I'm using a dependency called overblog/graphql-bundle. It has a bug and I want to override 1 specific file of that project: vendor/overblog/graphql-bundle/src/DependencyInjection/Compiler/TypeGeneratorPass.php.

I found a trick somewhere to define your file in autoload.files and then use exclude-from-classmap.

It worked fine.

Until I saw the ask to test 2.2.0-RC1, it broke.

Now this could be just fine, as what I'm doing is not what should be done, or it's a bug.

Either way, I wanted to report it :)

My composer.json:

{
    "name": "my/project",
    "autoload": {
        "psr-4": {
            "App\\": "src"
        },
        "files": [
            "src/Forked/OverblogGraphQLBundle/TypeGeneratorPass.php"
        ],
        "exclude-from-classmap": [
            "vendor/overblog/graphql-bundle/src/DependencyInjection/Compiler/TypeGeneratorPass.php"
        ]
    },
    "require": {
        "overblog/graphql-bundle": "dev-master",
        "symfony/dependency-injection": "^5.3"
    }
}

The file that I forked:

<?php
// src/Forked/OverblogGraphQLBundle/TypeGeneratorPass.php

declare(strict_types=1);

namespace Overblog\GraphQLBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class TypeGeneratorPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {

    }
}

Output of composer diagnose:

Running 2.2.0-RC1 (2021-12-08 15:17:19) with PHP 8.0.13 on Darwin / 21.1.0
Reading ./composer.json (/Volumes/CS/www/website/composer.json)
Loading config file /Users/Ruud/.composer/auth.json
Loading config file ./composer.json (/Volumes/CS/www/website/composer.json)
Checked CA file /opt/homebrew/etc/ca-certificates/cert.pem: valid
Executing command (/Volumes/CS/www/website): git branch -a --no-color --no-abbrev -v
Executing command (/Volumes/CS/www/website): git rev-list main..ruudk/composer-rc
Reading /Users/Ruud/.composer/composer.json
Loading config file /Users/Ruud/.composer/auth.json
Loading config file /Users/Ruud/.composer/composer.json (/Users/Ruud/.composer/composer.json)
Loading config file /Users/Ruud/.composer/auth.json
Reading /Users/Ruud/.composer/auth.json
Reading /Volumes/CS/www/website/vendor/composer/installed.json
Reading /Users/Ruud/.composer/vendor/composer/installed.json
PHP Fatal error:  Uncaught Error: Interface "Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface" not found in /Volumes/CS/www/website/src/Forked/OverblogGraphQLBundle/TypeGeneratorPass.php:10
Stack trace:
#0 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(1422): require()
#1 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Plugin/PluginManager.php(244): Composer\Autoload\composerRequire('11b4516c0f32201...', 'src/Forked/Over...')
#2 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Plugin/PluginManager.php(469): Composer\Plugin\PluginManager->registerPackage(Object(Composer\Package\CompletePackage), false, false)
#3 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Plugin/PluginManager.php(102): Composer\Plugin\PluginManager->loadRepository(Object(Composer\Repository\InstalledFilesystemRepository), false)
#4 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Factory.php(437): Composer\Plugin\PluginManager->loadInstalledPlugins()
#5 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Factory.php(638): Composer\Factory->createComposer(Object(Composer\IO\ConsoleIO), Array, false)
#6 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Console/Application.php(437): Composer\Factory::create(Object(Composer\IO\ConsoleIO), NULL, false)
#7 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Command/BaseCommand.php(64): Composer\Console\Application->getComposer(false, false)
#8 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Command/BaseCommand.php(143): Composer\Command\BaseCommand->getComposer(false, false)
#9 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Command/Command.php(211): Composer\Command\BaseCommand->initialize(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Application.php(835): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Composer\Command\DiagnoseCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Console/Application.php(332): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Application.php(117): Composer\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Console/Application.php(128): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/bin/composer(73): Composer\Console\Application->run()
#16 /opt/homebrew/Cellar/composer/2.1.14/bin/composer(29): require('phar:///opt/hom...')
#17 {main}
  thrown in /Volumes/CS/www/website/src/Forked/OverblogGraphQLBundle/TypeGeneratorPass.php on line 10

When I run this command:

composer u

I get the following output:

PHP Fatal error:  Uncaught Error: Interface "Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface" not found in /Volumes/CS/www/website/src/Forked/OverblogGraphQLBundle/TypeGeneratorPass.php:10
Stack trace:
#0 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Autoload/AutoloadGenerator.php(1422): require()
#1 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Plugin/PluginManager.php(244): Composer\Autoload\composerRequire('11b4516c0f32201...', 'src/Forked/Over...')
#2 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Plugin/PluginManager.php(469): Composer\Plugin\PluginManager->registerPackage(Object(Composer\Package\CompletePackage), false, false)
#3 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Plugin/PluginManager.php(102): Composer\Plugin\PluginManager->loadRepository(Object(Composer\Repository\InstalledFilesystemRepository), false)
#4 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Factory.php(437): Composer\Plugin\PluginManager->loadInstalledPlugins()
#5 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Factory.php(638): Composer\Factory->createComposer(Object(Composer\IO\ConsoleIO), Array, false)
#6 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Console/Application.php(437): Composer\Factory::create(Object(Composer\IO\ConsoleIO), NULL, false)
#7 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Command/BaseCommand.php(64): Composer\Console\Application->getComposer(false, false)
#8 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Command/BaseCommand.php(143): Composer\Command\BaseCommand->getComposer(false, false)
#9 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Command/Command.php(211): Composer\Command\BaseCommand->initialize(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Application.php(835): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Composer\Command\DiagnoseCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Console/Application.php(332): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/vendor/symfony/console/Application.php(117): Composer\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/src/Composer/Console/Application.php(128): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 phar:///opt/homebrew/Cellar/composer/2.1.14/bin/composer/bin/composer(73): Composer\Console\Application->run()
#16 /opt/homebrew/Cellar/composer/2.1.14/bin/composer(29): require('phar:///opt/hom...')
#17 {main}
  thrown in /Volumes/CS/www/website/src/Forked/OverblogGraphQLBundle/TypeGeneratorPass.php on line 10

And I expected this to happen:

No error

@ruudk ruudk changed the title [2.2.0-RC1] AutoloadGenerator.php when overriding a file using autoload.files + autoload.exclude-from-classmap [2.2.0-RC1] AutoloadGenerator.php crashes when overriding a file using autoload.files + autoload.exclude-from-classmap Dec 8, 2021
@Seldaek
Copy link
Member

Seldaek commented Dec 10, 2021

The proper way IMO for your hack would be:

        "psr-4": {
            "Overblog\\GraphQLBundle\\DependencyInjection\\Compiler\\": "src/Forked/OverblogGraphQLBundle/"
        }

Instead of files+exclude-from-classmap.

That will ensure that when the class is loaded, the one from your package takes precedence over the dependent one. The files hack just forces it to load it always which is kinda wasteful and messy (and breaks here..).

@Seldaek Seldaek added this to the 2.2 milestone Dec 10, 2021
@ruudk
Copy link
Contributor Author

ruudk commented Dec 12, 2021

Thanks for the explanation. I'll try that, let's close this.

@ruudk ruudk closed this as completed Dec 12, 2021
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

2 participants