When regenerating the xmlsitemap using drush 10, an error occurs:
InvalidArgumentException: Route required in Drupal\Core\Url::fromRouteMatch()

I'm not sure why or how this would happen. Though, I did find a workaround: instead of using batch_process, use the drush-equivalent drush_backend_batch_process.

I'll add a small patch for review.

Comments

SpadXIII created an issue. See original summary.

spadxiii’s picture

Status: Active » Needs review
StatusFileSize
new495 bytes
dave reid’s picture

Status: Needs review » Postponed (maintainer needs more info)

The Drush commands should be already using drush_backend_batch_process() in src/Commands/XmlSitemapCommands.php. What command are you running? Can you maybe provide some verbose output of the command?

dave reid’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new326 bytes

Actually looks like we need to make this change to allow it to work with Drush 10.

spadxiii’s picture

I was using 'drush cron', so not a specific drush command for regeneration.

I'll check that change coming week to see if that also works.

dave reid’s picture

I would be curious why an unprogressive batch is failling when being run in Drush. I would not expect it to fail at all. I'm going to commit #4 in the meantime since we do want to enable Drush 10 support for our custom commands.

  • Dave Reid committed d4ab9c5 on 8.x-1.x
    Issue #3100808 by Dave Reid: Added support for Drush 10.
    
dave reid’s picture

Status: Needs review » Postponed (maintainer needs more info)
alfattal’s picture

I'm having the same issue. The cron job fail to run even from the admin UI. Error

message returned when running cron with drush:

[error] InvalidArgumentException: Route required in Drupal\Core\Url::fromRouteMatch() (line 159 of /mnt/www/html/mndordev/docroot/core/lib/Drupal/Core/Url.php).

Update: Downgrading to Drush 9.7.2 did solve the problem until recently. I've noticed that the cron jod is returning the same error message with the XML sitemap not been updated.

oheller’s picture

I'm having a similar issue. My sitemap isn't being regenerated when I run cron from Drush 10:
```
drush cron
[notice] Starting execution of acquia_connector_cron().
[notice] Starting execution of captcha_cron(), execution of acquia_connector_cron() took 0.04ms.
[notice] Starting execution of field_cron(), execution of captcha_cron() took 1.32ms.
[notice] Starting execution of file_cron(), execution of field_cron() took 0.47ms.
[notice] Starting execution of history_cron(), execution of file_cron() took 40.46ms.
[notice] Starting execution of layout_builder_cron(), execution of history_cron() took 0.71ms.
[notice] Starting execution of lightning_scheduler_cron(), execution of layout_builder_cron() took 9.11ms.
[notice] Starting execution of node_cron(), execution of lightning_scheduler_cron() took 19.6ms.
[notice] Starting execution of purge_processor_cron_cron(), execution of node_cron() took 0.02ms.
[notice] Starting execution of search_api_cron(), execution of purge_processor_cron_cron() took 102.92ms.
[notice] Starting execution of search_api_solr_cron(), execution of search_api_cron() took 23.07ms.
[notice] Starting execution of simple_oauth_cron(), execution of search_api_solr_cron() took 0.34ms.
[notice] Starting execution of system_cron(), execution of simple_oauth_cron() took 4.64ms.
[notice] Starting execution of webform_cron(), execution of system_cron() took 35.25ms.
[notice] Starting execution of xmlsitemap_engines_cron(), execution of webform_cron() took 10.65ms.
[notice] Starting execution of xmlsitemap_cron(), execution of xmlsitemap_engines_cron() took 0.33ms.
[notice] Execution of xmlsitemap_cron() took 0.31ms.
[notice] Cron run completed.
```

I'm using:
Drupal 8.8.1
Apache 2.4.18 (Ubuntu)
php 7.2
db 5.7.28
drush 10.1.1
Vagrant/blt
drupal/xmlsitemap:1.x-dev
drupal/xmlsitemap:8.x-1.0-rc1

I've set the minimum time to none, and disable cron generation is off. Dev mode is off.
I have a around 3000 aliased urls. To test I've been deleting all the aliases or generating the aliases.

By turning dev mode on I get the `InvalidArgumentException: Route required in Drupal\Core\Url::fromRouteMatch() (line 159 of /var/www/mndor/docroot/core/lib/Drupal/Core/Url.php).` error. After running cron manually from the UI, this error goes away, but the sitemap still isn't updated.

I've only been running `drush cron` in attempt to update the sitemap because I have a number of other functions tied to cron.

pookmish’s picture

I've encountered this same error with Drush 9.7.2, Drupal 8.8.4.
The patch in #2 solved it for me.

alfattal’s picture

@pookmish The patch in #2 stopped the error message from showing, but it did not resolve the problem. When running drush cron, I can see that it's successful, the same applies when running the cron job from the Admin UI. But, when checking the sitemap.xml file, it was not updated. Can you confirm that it's been updated in your case?

pookmish’s picture

@alfattal I just double checked and it does indeed update the sitemap.xml for me. I had two separate scenarios:

  1. after a fresh site install, the /sitemap.xml gave a 404 response.
    • Without the patch, I run cron and the error is observed and the page is still 404
    • With the patch, I run cron and the error does not occur. The /sitemap.xml page now produces a sitemap.
  2. The /sitemap.xml response is 200. After I create a new node and run cron, the /sitemap.xml is updated.
alfattal’s picture

@pookmish Thank you for your response. That's indeed interesting. Wonder what that is conflicting with the cron job on my site. Any idea where to dig?!

bvoynick’s picture

After updating Drupal Core (8.7.x -> 8.8.5) and xmlsitemap to rc1, I encountered the same issue when running "drush cron". Drush 9.7.2 (was 9.7.1 I believe.)

#2 worked for me as well. No more error, and on the next regeneration I see a new custom link that hadn't shown up previously.

marcoscano’s picture

Title: Drush 10 gives error when regenerating in cron » "InvalidArgumentException: Route Required" exception when running cron through drush
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new642.79 KB

Here's a screenshot of the stack trace when the problem happens, in case it's helpful.

I'm running just drush cron, and this environment is on:
- Drupal 8.8.5
- drupal/xmlsitemap: dev-1.x#379953245cba320e98100424e0ccb0d726105f7f
- Drush 9.7.2

I can confirm patch #2 makes the error go away.

alfattal’s picture

@marcoscano In my case, patch #2 fixed the error message when running drush cron, but it didn't update the sitemap.xml file. I have to run drush xmlsitemap:regenerate to update the sitemap

Update: It turns out that the Minimum sitemap lifetime was set to (1 day) the default settings, which is why the sitemap.xml file was not being updated when I run drush cron. Setting it to (No minimum), I was able to execute the cron job successfully with no errors and update the sitemap.

I confirm that patch in #2 solved the issue for me.

My environment is on:
- Drupal core 8.8.5
- drupal/xmlsitemap: 8.x-1.0-rc1
- Drush: 9.7.2

didier misson’s picture

same error

D8.7.13
With Drush 9.7.1, "drush cron" run correctly.
After upgrading Drush to 9.7.2, "drush cron" give the same error :

[notice] Starting execution of scheduler_cron(), execution of node_cron() took 5.91ms.
[notice] Starting execution of search_cron(), execution of scheduler_cron() took 4.27ms.
[notice] Starting execution of simple_sitemap_cron(), execution of search_cron() took 5.81ms.
[error] InvalidArgumentException: Route required in Drupal\Core\Url::fromRouteMatch() (line 158 of /home/mysite/public_html/thunder/docroot/core/lib/Drupal/Core/Url.php).
[notice] Starting execution of system_cron(), execution of simple_sitemap_cron() took 17.16ms.
[notice] Starting execution of update_cron(), execution of system_cron() took 5.36ms.
[notice] Execution of update_cron() took 11.61ms.

I restore the vendor/drush folder to drush 9.7.1, and drush cron is correct.

Why ?
Thanks

nevergone’s picture

Status: Needs review » Reviewed & tested by the community

Patch #2 tested and works well!

ytsurk’s picture

Status: Reviewed & tested by the community » Closed (outdated)

If patch #2 applies you're not using the latest version.

This is fixed in RC1. Make sure to regenerate the sitemap (drush xmlsitemap:regenerate) to make the error disappear.

pookmish’s picture

Status: Closed (outdated) » Active

@ytsurk

If patch #2 applies you're not using the latest version.

This is incorrect. The patch can be applied to the latest RC1 version and I have done so with several use cases.

This is fixed in RC1. Make sure to regenerate the sitemap (drush xmlsitemap:regenerate) to make the error disappear.

This is not fixed in RC1. The issue reported is not about the drush xmlsitemap:regenerate command. The module should function without the need to run the drush command. It should function 100% via cron.

pookmish’s picture

Status: Active » Reviewed & tested by the community
ytsurk’s picture

You're right .. I did not look good enough, the patch applies. Sorry for the confusion.

For me, regeneration of the sitemap via UI or drush made the error disappear, when running drush cron afterwards. So no need for a code change, IMO.
Maybe an update hook could regenerate the sitemap to solve it for all.

And the question remains, is the sitemap updated via cron or not - this needs investigation .. so you say the patch makes the sitemap updating again?

dave reid’s picture

StatusFileSize
new2.06 KB

Okay I understand the issue now is running the drush cron command. Re-rolled #2 with simplifying dependencies and removing the need for the bridge test assertions since Drupal 8.8 requires at least PHPUnit 6+.

dave reid’s picture

StatusFileSize
new3.15 KB

This should fix the test failures.

  • Dave Reid committed dec3b50 on 8.x-1.x
    Issue #3100808 by Dave Reid, SpadXIII, marcoscano: Fixed errors when...
dave reid’s picture

Status: Reviewed & tested by the community » Fixed

Tested and committed #25 to 8.x-1.x:

➜  drupal-88 drush cron --verbose
 [notice] Starting execution of comment_cron().
 [notice] Starting execution of dblog_cron(), execution of comment_cron() took 41.31ms.
 [notice] Starting execution of field_cron(), execution of dblog_cron() took 3.21ms.
 [notice] Starting execution of file_cron(), execution of field_cron() took 8.22ms.
 [notice] Starting execution of history_cron(), execution of file_cron() took 148ms.
 [notice] Starting execution of layout_builder_cron(), execution of history_cron() took 4.7ms.
 [notice] Starting execution of node_cron(), execution of layout_builder_cron() took 59.19ms.
 [notice] Starting execution of search_cron(), execution of node_cron() took 40.85ms.
 [notice] Starting execution of system_cron(), execution of search_cron() took 46.63ms.
 [notice] Starting execution of update_cron(), execution of system_cron() took 41.97ms.
 [notice] Starting execution of xmlsitemap_cron(), execution of update_cron() took 178.42ms.
 [info] Executing: /home/davereid/opt/drush.phar batch-process 5 --uri=https://88.drupal.test/ --root=/mnt/c/Projects/drupal-88/web
>  [notice] Generated https://88.drupal.test/sitemap.xml?page=1 with 1 links.
>  [notice] Finished XML sitemap generation in 0 sec. Memory usage: 32.5 MB.
>  [notice] Message: The sitemaps were regenerated.
>
 [notice] Execution of xmlsitemap_cron() took 4674.85ms.
 [notice] Cron run completed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.