Skip to content

[Icons] ux:icons:lock fails #2719

Open
@ameotoko

Description

@ameotoko

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions