Problem/Motivation
If an error happens during the REST call, the module tries to display a message about the error to the user and crashes because of a wrong call to ->mesenger.
Error:
The website encountered an unexpected error. Try again later. Error: Call to a member function addError() on null in Drupal\azure_mailer\Plugin\Mail\AzureMailer->mail() (line 129 of modules/contrib/azure_mailer/src/Plugin/Mail/AzureMailer.php). Drupal\mailsystem\Adapter->mail() (Line: 308) Drupal\Core\Mail\MailManager->doMail() (Line: 181) Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 637) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 180) Drupal\Core\Mail\MailManager->mail() (Line: 70) Drupal\mailsystem\MailsystemManager->mail() (Line: 109) Drupal\mail_debugger\Form\MailDebuggerForm->submitForm() call_user_func_array() (Line: 129) Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 67) Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597) Drupal\Core\Form\FormBuilder->processForm() (Line: 326) Drupal\Core\Form\FormBuilder->buildForm() (Line: 73) Drupal\Core\Controller\FormController->getContentResult() call_user_func_array() (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 637) Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181) Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76) Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53) Drupal\Core\StackMiddleware\Session->handle() (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28) Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 116) Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90) Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36) Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51) Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741) Drupal\Core\DrupalKernel->handle() (Line: 19)
Steps to reproduce
Use a wrong Azure URL and try to send a mail.
Proposed resolution
Change:
$this->messenger->addError('Azure Communication Services error: ' . $e->getMessage());
To:
$this->messenger()->addError('Azure Communication Services error: ' . $e->getMessage());
in: https://git.drupalcode.org/project/azure_mailer/-/blob/2.0.x/src/Plugin/...
Explanation:
The issue is you’re calling the property $this->messenger, which is null unless you explicitly inject it. MessengerTrait only guarantees the method messenger() that lazy-loads the service.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3541803-azure_mailer-fix_call_to_member_on_null.patch | 708 bytes | marcusx |
Comments
Comment #2
marcusx commentedPatch...
Comment #3
smustgrave commentedpatch seems straight forward and that is correct for using the MessengerTrait.
Comment #4
jeffschulerPatch working here. Thanks!
Comment #6
smustgrave commented