Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] flatternException->getTraceAsString() returns null sometimes, which causes exceptions #32487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wtorsi opened this issue Jul 10, 2019 · 2 comments

Comments

@wtorsi
Copy link

wtorsi commented Jul 10, 2019

4.3.2

When $flattenException is built from $lastRedeliveryStamp in Symfony\Component\Messenger\Command\AbstractFailedMessagesCommand:76 it may contains null in traceAsString. Which causes exceptions in Symfony\Component\Messenger\Command\AbstractFailedMessagesCommand:103, because SymfonyStyle does not like nulls as messages.

        $flattenException = null === $lastRedeliveryStamp ? null : $lastRedeliveryStamp->getFlattenException();
            $io->title('Exception:');
            $io->writeln(null === $flattenException ? '(no data)' : $flattenException->getTraceAsString());

Actually, I don't know how to simply reproduce this exception.
I got this exception, trying sending Email through Mailer, while generating body in Email. (A message must have a text and/or an HTML part.)

As a solution i could recommend the following:

  1. Add strong (?string) type-hinting for Symfony\Component\Debug\Exception\FlattenException::getTraceAsString
  2. Do check not only for null === $flattenException in Symfony\Component\Messenger\Command\AbstractFailedMessagesCommand:103, but either check null === $flattenException->getTraceAsString()`
@wtorsi
Copy link
Author

wtorsi commented Jul 10, 2019

Ah, the problem occurs, while serializing TemplatedEmail before sending it into the bus in Mailer. :)

    public function send(RawMessage $message, SmtpEnvelope $envelope = null): void
    {
        if (null === $this->bus) {
            $this->transport->send($message, $envelope);

            return;
        }

        $this->bus->dispatch(new SendEmailMessage($message, $envelope));
    }

Serializer is trying to getBody of TemplatedEmail, but the body at this moment is empty, no $html and $text parameters were set yet. So it's another small issue in Mailer.

@fabpot
Copy link
Member

fabpot commented Aug 18, 2020

Should be fixed by #37847

@fabpot fabpot closed this as completed Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants