MessengerPass::getServiceClass() must be of the type string, null returned
Fabian Blechschmidt
You are implement a scheduled task in Shopware 6 and get a weird error message?
-> % ddev console scheduled-task:register
TypeError {#12307
#message: "Return value of Symfony\Component\Messenger\DependencyInjection\MessengerPass::getServiceClass() must be of the type string, null returned"
#code: 0
#file: "./vendor/symfony/messenger/DependencyInjection/MessengerPass.php"
#line: 394
trace: {
./vendor/symfony/messenger/DependencyInjection/MessengerPass.php:394 { …}
./vendor/symfony/messenger/DependencyInjection/MessengerPass.php:86 { …}
./vendor/symfony/messenger/DependencyInjection/MessengerPass.php:71 { …}
./vendor/symfony/dependency-injection/Compiler/Compiler.php:82 { …}
./vendor/symfony/dependency-injection/ContainerBuilder.php:757 { …}
./vendor/symfony/http-kernel/Kernel.php:546 { …}
./vendor/shopware/core/Kernel.php:193 { …}
./vendor/symfony/framework-bundle/Console/Application.php:168 { …}
./vendor/symfony/framework-bundle/Console/Application.php:74 { …}
./vendor/symfony/console/Application.php:171 { …}
./bin/console:74 {
› $application = new Application($kernel->getKernel());
› $application->run($input);
›
arguments: {
$input: Symfony\Component\Console\Input\ArgvInput {#3 …}
}
}
}
}
Then you maybe copied the classnames of your TaskHandler and/or Task with a \ prefix.
This is wrong:
<service id="\My\Module\ScheduledTask\UnpaidOrdersTask">
<tag name="shopware.scheduled.task"/>
</service>
<service id="\My\Module\ScheduledTask\UnpaidOrdersTaskHandler">
<argument type="service" id="scheduled_task.repository"/>
<tag name="messenger.message_handler"/>
</service>
This is correct:
<service id="My\Module\ScheduledTask\UnpaidOrdersTask">
<tag name="shopware.scheduled.task"/>
</service>
<service id="My\Module\ScheduledTask\UnpaidOrdersTaskHandler">
<argument type="service" id="scheduled_task.repository"/>
<tag name="messenger.message_handler"/>
</service>
The difference? The id:
My\Module\ScheduledTask\UnpaidOrdersTask
\My\Module\ScheduledTask\UnpaidOrdersTask
I hope this helps someone 🙂
Other articles from this category
ENABLE_SERVICES: the Shopware env var that quietly installs apps on your shop
I was grepping through vendor/shopware/core for the hidden-gems series and stumbled over Shopware\Core\Service\AllServiceInstaller. Two-argument constructor, twelve lines of logic, @internal. Nothing dramatic — until I read what it actually does: it installs apps on your shop. By itself. In production. Once a day. Unless you told it not to. So this one isn’t going to […]
Shopware 6 Hidden Gems #24: Lightning round — ten small gems that didn’t need their own post
Twenty-three parts into this series, my research folder still has a stack of finds that are real, useful, undocumented — and about two paragraphs big. Instead of stretching each into a full post, here’s the lightning round. One problem, one gem, one file reference. Go. 1. rawUrl() — URLs for mail templates that actually work […]
Shopware 6 Hidden Gems #23: Why your sitemap silently stopped updating (and sitemap:generate –force)
A slow-burn bug report, verbatim from memory: „Google Search Console shows our sitemap is three months old. New categories aren’t in it.“ Three months. No errors in the log worth noticing, the scheduled task looks healthy, and regenerating „worked“ — or seemed to. The cause turned out to be a mechanism that’s completely reasonable and […]