8000 [Icons] `ux:icons:lock` fails · Issue #2719 · symfony/ux · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Icons] ux:icons:lock fails #2719

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

Open
ameotoko opened this issue May 7, 2025 · 1 comment · May be fixed by #2723
Open

[Icons] ux:icons:lock fails #2719

ameotoko opened this issue May 7, 2025 · 1 comment · May be fixed by #2723
Labels
Bug Bug Fix Icons Status: Needs Review Needs to be reviewed

Comments

@ameotoko
Copy link
ameotoko commented May 7, 2025

Executing ux:icons:lock in my application throws an exception:

You must call one of in() or append() methods before iterating over a Finder.  
                                                                                 

Exception trace:
  at /Users/andrey/Sites/nations/vendor/symfony/finder/Finder.php:667
 Symfony\Component\Finder\Finder->getIterator() at /Users/andrey/Sites/nations/vendor/symfony/ux-icons/src/Twig/IconFinder.php:74
 Symfony\UX\Icons\Twig\IconFinder->templateFiles() at /Users/andrey/Sites/nations/vendor/symfony/ux-icons/src/Twig/IconFinder.php:81
 Symfony\UX\Icons\Twig\IconFinder->templateFiles() at /Users/andrey/Sites/nations/vendor/symfony/ux-icons/src/Twig/IconFinder.php:45
 Symfony\UX\Icons\Twig\IconFinder->icons() at /Users/andrey/Sites/nations/vendor/symfony/ux-icons/src/Command/LockIconsCommand.php:64
 Symfony\UX\Icons\Command\LockIconsCommand->execute() at /Users/andrey/Sites/nations/vendor/symfony/console/Command/Command.php:279
 Symfony\Component\Console\Command\Command->run() at /Users/andrey/Sites/nations/vendor/symfony/console/Application.php:1094
 Symfony\Component\Console\Application->doRunCommand() at /Users/andrey/Sites/nations/vendor/symfony/framework-bundle/Console/Application.php:123
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /Users/andrey/Sites/nations/vendor/symfony/console/Application.php:342
 Symfony\Component\Console\Application->doRun() at /Users/andrey/Sites/nations/vendor/symfony/framework-bundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/andrey/Sites/nations/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->run() at /Users/andrey/Sites/nations/vendor/contao/manager-bundle/bin/contao-console:40
 include() at /Users/andrey/Sites/nations/vendor/bin/contao-console:119

It comes from the Finder call in this method:

private function templateFiles(LoaderInterface $loader): iterable
{
if ($loader instanceof FilesystemLoader) {
$paths = [];
foreach ($loader->getNamespaces() as $namespace) {
$paths = [...$paths, ...$loader->getPaths($namespace)];
}
foreach ((new Finder())->files()->in($paths)->name('*.twig') as $file) {
yield (string) $file;
}
}

The application uses a chain of loaders, last of which is normal Twig\Loader\FilesystemLoader. $loader->getNamespaces() returns empty array, so the $paths is also an empty array, which makes Finder throw.

Adding simple if (!empty($paths)) check fixed it for me, but if it's not correct then I will need some help. This is not a pure Symfony app, but an instance of Contao CMS, which is built on top of Symfony, so may be some configuration needs to be adjusted instead. I am ready to debug it further if somebody points me to the right direction.

@ameotoko ameotoko added the Bug Bug Fix label May 7, 2025
@carsonbot carsonbot added Icons Status: Needs Review Needs to be reviewed labels May 7, 2025
@smnandre
Copy link
Member
smnandre commented May 8, 2025

@ameotoko i'd say let's use the occasion to patch / add the default namespace

    private function templateFiles(LoaderInterface $loader): iterable
    {
        if ($loader instanceof FilesystemLoader) {
            $paths = $loader->getPaths();
            foreach ($loader->getNamespaces() as $namespace) {
                $paths = [...$paths, ...$loader->getPaths($namespace)];
            }
            if ($paths) {
                foreach ((new Finder())->files()->in($paths)->name('*.twig') as $file) {
                    yield (string) $file;
                }
            }
        }

        if ($loader instanceof ChainLoader) {
            foreach ($loader->getLoaders() as $subLoader) {
                yield from $this->templateFiles($subLoader);
            }
        }
    }

Would you like to open a PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Icons Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0