Seldaek/monolog · error · InvalidArgumentException

You must provide either a Swift_Message instance or a callab

Error message

You must provide either a Swift_Message instance or a callable returning it

What it means

Error "You must provide either a Swift_Message instance or a callable returning it" thrown in Seldaek/monolog.

Source

Thrown at src/Monolog/Handler/MandrillHandler.php:44

    protected string $apiKey;

    /**
     * @phpstan-param (Swift_Message|callable(): Swift_Message) $message
     *
     * @param string                 $apiKey  A valid Mandrill API key
     * @param callable|Swift_Message $message An example message for real messages, only the body will be replaced
     *
     * @throws \InvalidArgumentException if not a Swift Message is set
     */
    public function __construct(string $apiKey, callable|Swift_Message $message, int|string|Level $level = Level::Error, bool $bubble = true)
    {
        parent::__construct($level, $bubble);

        if (!$message instanceof Swift_Message) {
            $message = $message();
        }
        if (!$message instanceof Swift_Message) {
            throw new \InvalidArgumentException('You must provide either a Swift_Message instance or a callable returning it');
        }
        $this->message = $message;
        $this->apiKey = $apiKey;
    }

    /**
     * @inheritDoc
     */
    protected function send(string $content, array $records): void
    {
        $mime = 'text/plain';
        if ($this->isHtmlBody($content)) {
            $mime = 'text/html';
        }

        $message = clone $this->message;
        $message->setBody($content, $mime);
        /** @phpstan-ignore-next-line */

View on GitHub (pinned to 57eb102834)

When it happens

Trigger: Thrown at src/Monolog/Handler/MandrillHandler.php:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Seldaek/monolog@57eb102834 (2026-08-17). Data as JSON: /api/errors/1c83833110888fc0. Report an issue: GitHub.