Skip to content

[Scheduler] Using before, after or onFailure methods causes unhandled exception when not configured #53722

@CoalaJoe

Description

@CoalaJoe

Symfony version(s) affected

6.4

Description

According to the documentation at:
https://symfony.com/doc/current/scheduler.html#a-strategic-event-handling
image

Using those functions like that does not work and results in a 500 error

{"message":"Uncaught Error: Call to a member function addListener() on null","context":{"exception":{"class":"Error","message":"Call to a member function addListener() on null","code":0,"file":"/app/vendor/symfony/scheduler/Schedule.php:144"}},"channel":"php","extra":{},"severity":"CRITICAL","time":"2024-02-01T13:22:04.559+01:00"}

How to reproduce

     // ...
    public function getSchedule(): Schedule
    {
        $this->schedule ??= (new Schedule())
            ->with(...$this->getGeneralMessages(), ...$this->getProductionMessages())
            ->before(function (PreRunEvent $event) {
                $this->logger?->info('Before Event');
            })
            ->after(function (PostRunEvent $event) {
                $this->logger?->info('After Event');
            })
            ->onFailure(function (FailureEvent $event) {
                $this->logger?->info('Failure Event');
                $this->logger?->info($event->getError()->getMessage());
            })
            ->lock($this->lockFactory->createLock('cron-cache'))
            ->stateful($this->cache);

        return $this->schedule;
    }

Possible Solution

Either update documentaiton, add error handling and throw our own exception or fail silently and log an error?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy