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
PHPStorm/IDEA, composer updates and 100% CPU
In one of our projects PHPStorm ran a while on 100% CPU, an investigation showed, that the process „checking for available composer updates“ ran and used all the resources. Most likely it got stuck somewhere. To get rid of the problem, one can turn off this feature. In IDEA Ultimate here: [Settings] -> Languages & […]
Custom Fields, dots and MySQL’s JSON_EXTRACT
We all know custom fields – hopefully – at least this is not about the basics. You can add custom fields to nearly all entites: orders, products, categories, … You can name them whatever you like, e.g. pluginname.property – but using dots . in your custom field name is a bad idea, because then you […]
gpg failed to sign the data
I was doing some work, when suddenly my git failed to commit changed. I dig a little around, asked StackOverflow but it didn’t help. Finally when running the commit manually and not through PHPStorm I got a proper error: Ah! The key is expired! Got it. Did you know you can extend a GPG key? […]