TypeError in LinkStatusHandle.php

Created on 1 November 2021, over 3 years ago
Updated 20 January 2023, over 2 years ago

I'm getting the following error when running cron with Link Checker enabled on several 9.2.7 sites:

TypeError: Argument 1 passed to Drupal\linkchecker\Plugin\LinkStatusHandlerBase::handle() must implement interface Drupal\linkchecker\LinkCheckerLinkInterface, null given, called in /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/QueueWorker/LinkStatusHandle.php on line 79 in /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/LinkStatusHandlerBase.php on line 107 #0 /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/QueueWorker/LinkStatusHandle.php(79): Drupal\linkchecker\Plugin\LinkStatusHandlerBase->handle(NULL, Object(GuzzleHttp\Psr7\Response))
#1 /Users/dicksb/Sites/MAMP/moweb/docroot/core/lib/Drupal/Core/Cron.php(182): Drupal\linkchecker\Plugin\QueueWorker\LinkStatusHandle->processItem(Array)
#2 /Users/dicksb/Sites/MAMP/moweb/docroot/core/lib/Drupal/Core/Cron.php(147): Drupal\Core\Cron->processQueues()
#3 /Users/dicksb/Sites/MAMP/moweb/docroot/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()
#4 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/src/Drupal/Commands/core/DrupalCommands.php(76): Drupal\Core\ProxyClass\Cron->run()
#5 [internal function]: Drush\Drupal\Commands\core\DrupalCommands->cron(Array)
#6 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#7 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#8 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#9 /Users/dicksb/Sites/MAMP/moweb/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(313): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /Users/dicksb/Sites/MAMP/moweb/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#17 /Users/dicksb/Sites/MAMP/moweb/vendor/drush/drush/drush(4): require('/Users/dicksb/S...')
#18 {main}
TypeError: Argument 1 passed to Drupal\linkchecker\Plugin\LinkStatusHandlerBase::handle() must implement interface Drupal\linkchecker\LinkCheckerLinkInterface, null given, called in /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/QueueWorker/LinkStatusHandle.php on line 79 in Drupal\linkchecker\Plugin\LinkStatusHandlerBase->handle() (line 107 of /Users/dicksb/Sites/MAMP/moweb/docroot/modules/contrib/linkchecker/src/Plugin/LinkStatusHandlerBase.php).
 [warning] Drush command terminated abnormally.

I cannot entirely reproduce this. A fresh install using the same core and the same custom install profile seems able to run cron just fine with Link Checker enabled, while (so far) about a half-dozen existing sites (also on the same core) started experiencing this error when Link Checker was enabled.

Uninstalling Link Checker stops the error. Reinstalling it causes the error to return, even if I don't configure any fields to be checked.

Error occurs both on Acquia Cloud and on my local MAMP environment.

Problem occurs with both 1.0-beta and 1.x-dev.

On a fresh install, I cannot reproduce the error even if I enable all the modules that are enabled on the sites where the error occurs.

I'm still trying to isolate this, but I'm hoping someone else may have an idea.

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wrd-oaitsd

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States aitala

    Hi,

    Patch seems to work...

    No idea why the error was occurring - Is a new Drupal 9 site...

    Eric

  • πŸ‡¦πŸ‡ΊAustralia timfletcher

    I tried Patch #11 after running into this πŸ› Argument #1 ($link) must be of type Drupal\linkchecker\LinkCheckerLinkInterface, null given Needs review on the 2.x D10 version, which suppresses the error but still WSODs the page. If the cause of the error isn't the cause of the WSOD, I have no idea what may be causing it.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    87 pass
  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    I updated the patch with proper array index checking, method argument type checking and catching Throwable to not produce WSOD if Exception or Error is thrown.

  • πŸ‡³πŸ‡±Netherlands promes

    patch #19 works for me.

  • πŸ‡¬πŸ‡§United Kingdom alt36

    I have a site which is currently throwing this error every time cron runs, and have been trying to figure out reproducible steps without success. However, I am reasonably confident about the following.

    I have linkchecker configured to update redirected links after three checks (error.action_status_code_301 = 3)

    I have two nodes which contain the same link (identical urlhash value in linkchecker_link table, lid=1643 and 1720, different entity_id__target_id values). The link returns 301 and both rows in linkchecker_link have fail_count=2. The queue table has a couple of hundred rows with name=linkchecker_status_handle. I've made a clone of my Drupal installation to debug and have manually executed "truncate queue".

    I run "drush cron". Manually watching the queue table I see many linkchecker_status_handle being created. The "TypeError .. null given" error is then thrown. The queue entry with the smallest item_id has data containing "s:5:"links";a:2:{i:1643;s:4:"1643";i:1720;s:4:"1720";}", i.e it will deserialize to links with lid 1643 and 1720. However, linkchecker_link no longer has the row with lid=1643 but the row for lid=1720 is still present. This presumably is what leads to the error: LinkStatusHandle::processItem() loads a null $link which gets passed unchecked to $hanlder->handle()

  • πŸ‡¬πŸ‡§United Kingdom joehuggans Harrogate, UK

    Tested patch #19 and seems to be working

Production build 0.71.5 2024