Closed
Description
Summary (*)
In developer mode, if an observer does not implement ObserverInterface, Magento throws an exception. This is the expected behavior.
What I don't understand is that it does not do anything for other deploy modes (default and production). It silently discards the observer without even putting an entry to logs.
Examples (*)
This is the method where problem occurs. There is only one condition for developer mode, but other deploy modes are ignored.
/**
* @param \Magento\Framework\Event\ObserverInterface $object
* @param Observer $observer
* @return $this
* @throws \LogicException
*/
protected function _callObserverMethod($object, $observer)
{
if ($object instanceof \Magento\Framework\Event\ObserverInterface) {
$object->execute($observer);
} elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
throw new \LogicException(
sprintf(
'Observer "%s" must implement interface "%s"',
get_class($object),
\Magento\Framework\Event\ObserverInterface::class
)
);
}
return $this;
}
Proposed solution
We can put an else condition. Then, we can log the same exception message in warning level.
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentIndicates that Pull Request has been created to fix issueThe issue has been reproduced on latest 2.3 release