reset(): Argument #1 ($array) must be of type array, null given

Created on 25 June 2024, 6 months ago

I am getting this error, not sure what I did wrong. Tried using hook_cron and Plugin option, both give the same error.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇪🇸Spain uridrupal

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

Merge Requests

Comments & Activities

  • Issue created by @uridrupal
  • 🇮🇳India abhishek_virasat

    Hello @UriDrupal, Could you please provide more information about the error, including the specific file and function where it is occurring? Additionally, please provide steps to reproduce the error, and specify which actions lead to this error.
    Thank you.

  • 🇪🇸Spain uridrupal

    I was using a hook_cron with a service inside. When I ran the hook_cron through simple_cron I got this error.
    The error was in src/CronJobManager.php

      /**
       * {@inheritdoc}
       */
      public function getEnabledJob(string $job_id): ?CronJobInterface {
        $jobs = $this->cronJobStorage->loadByProperties([
          'id' => $job_id,
          'status' => TRUE,
        ]);
    
        return $jobs ? reset($jobs) : NULL;
      }

    I couldn't figure out what was I doing wrong. Tried both the hook_cron way and the Plugin way, nothing worked. I am pretty sure it must have been something with my code, because the other jobs were working fine, but my hook_cron was just this:

    function hook_cron() {
      \Drupal::service('my_service')->myMethod();
    }
    
  • Assigned to abhishek_virasat
  • Merge request !7fixed the issue → (Merged) created by abhishek_virasat
  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • 🇮🇳India abhishek_virasat

    @UriDrupal, I have fixed the issue and created MR. please review it once.

  • Status changed to RTBC about 1 month ago
  • 🇬🇧United Kingdom scott_euser

    Certainly doesn't hurt to be more protective in the code like this.

  • Pipeline finished with Skipped
    9 days ago
    #367508
  • 🇬🇧United Kingdom scott_euser

    Thanks!

Production build 0.71.5 2024