8000 [Scheduler] Using before, after or onFailure methods causes unhandled exception when not configured · Issue #53722 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Scheduler] Using before, after or onFailure methods causes unhandled exception when not configured #53722
Closed
@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

      0