Debug "Success" message is duplicated and always set during queue processing

Created on 5 June 2024, 6 months ago

Problem/Motivation

The \Drupal\mailgun\MailgunHandler::sendMail method will log a success message when debug is turned on and an error message when an exception occurs. However when the message comes from a queue the \Drupal\mailgun\Plugin\QueueWorker\SendMailBase::processItem always logs a success message when debug is turned on regardless of whether the mail has been sent or not.

\Drupal\mailgun\MailgunHandler::sendMail

      $response = $this->mailgun->messages()->send($domain, $mailgunMessage);

      // Debug mode: log all messages.
      if ($this->mailgunConfig->get('debug_mode')) {
        $this->logger->notice('Successfully sent message from %from to %to. %id %message.',
          [
            '%from' => $mailgunMessage['from'],
            '%to' => $this->getRecipients($mailgunMessage),
            '%id' => $response->getId(),
            '%message' => $response->getMessage(),
          ]
        );
      }
      return $response;

\Drupal\mailgun\Plugin\QueueWorker\SendMailBase::processItem

  public function processItem($data) {
    $result = $this->mailgunHandler->sendMail($data->message);

    if ($this->mailgunConfig->get('debug_mode')) {
      $this->logger->notice('Successfully sent message on CRON from %from to %to.',
        [
          '%from' => $data->message['from'],
          '%to' => $data->message['to'],
        ]
      );
    }

    if (!$result) {
      throw new \Exception('Mailgun: email did not pass through API.');
    }
  }

Steps to reproduce

Turn on debug and queuing, and send a test email to a non existent/invalid email address that the API will reject e.g. 'test@example'. Process the queue and you will get an error message saying the API call failed, and a success message saying "Successfully sent message on CRON from Site email <...> to test@example."

Proposed resolution

As there is already a debug success message in \Drupal\mailgun\MailgunHandler::sendMail the simplest solution is to remove the one in \Drupal\mailgun\Plugin\QueueWorker\SendMailBase::processItem

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom altcom_neil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024