- Issue created by @ChrisDarke
- 🇬🇧United Kingdom ChrisDarke London
Closing Out - just realised this is coming from a patch from somewhere else that is modifying Mailchimp Transactional
Drupal 10.3.14, Mailchimp Transactional 1.1.4
When running a cron which sends out mail via Mailchimp Transactional, there was WSOD. I see that the backtrace shows this is coming from the fact that the TranslatableMarkup for an error is being called with an Array value being passed into it:
Original Error:
The website encountered an unexpected error. Try again later.
TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() (line 440 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Utility\Html::escape(Array) (Line: 268)
Drupal\Component\Render\FormattableMarkup::placeholderEscape(Array) (Line: 241)
Drupal\Component\Render\FormattableMarkup::placeholderFormat('Mailchimp Transactional: %error_message; %template_id; %template_content', Array) (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString() (Line: 54)
Drupal\Core\Messenger\Messenger->addMessage(Object, 'error', ) (Line: 46)
Drupal\Core\Messenger\Messenger->addError(Object) (Line: 199)
Drupal\mailchimp_transactional\API->sendTemplate(Array, 'dynamic-email-template', Array) (Line: 64)
REDACTED\Call\To\mailchimp_transactional
Drupal\Core\Cron->processQueue(Object, Object) (Line: 235)
Drupal\Core\Cron->processQueues() (Line: 70)
Drupal\ultimate_cron\UltimateCron->run() (Line: 70)
Drupal\ultimate_cron\ProxyClass\UltimateCron->run() (Line: 167)
Drupal\system\Form\CronForm->runCron(Array, Object)
call_user_func_array(Array, Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('system_cron_settings', Array, Object) (Line: 326)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The issue code is this:
\Drupal\mailchimp_transactional\API:198-217
if ($result instanceof RequestException) {
$this->messenger->addError(
$this->t(
'Mailchimp Transactional: %error_message; %template_id; %template_content', [
'%error_message' => $result->getMessage(),
'%template_id' => $template_id,
'%template_content' => $template_content,
]
)
);
$this->log->error($result->getMessage());
return [
(object) [
'status' => 'error',
'email' => $message['message']['to'][0]['email'] ?? 'recipient',
'message' => $result->getMessage()
]
];
}
Where $template_content is an array.
Call sendTemplate on Mailchimp Transactional with an error that means you will get a RequestException.
WSOD will occur.
Json encoding the array as per:
$this->t(
'Mailchimp Transactional: %error_message; %template_id; %template_content', [
'%error_message' => $result->getMessage(),
'%template_id' => (string) $template_id,
'%template_content' => JSON::encode($template_content),
]
);
Make MR
Test
Active
1.1
Code
Closing Out - just realised this is coming from a patch from somewhere else that is modifying Mailchimp Transactional