I updated easy_breadcrumb from 2.0.2 to 2.0.5 and some, but not all, URLs crash Drupal with a page containing just the following text:
UnexpectedValueException: base:category/article-content/activism-politics has no corresponding route. in Drupal\Core\Url->getRouteName() (line 567 of core/lib/Drupal/Core/Url.php).
This bug appears to have been introduced in 2.0.4. 2.0.3 seems fine and the problem first appears in 2.0.4.
Details:
Drupal core 9.5.9 (can't update to 10 until easy_breadcrumb 2.x works correctly)
easy_breadcrumb 2.0.4
easy_breadcrumb config:
The following checkboxes are set
- Applies to administration pages
- Include the current page as a segment in the breadcrumb
- Include the front page as a segment in the breadcrumb
- Use the real page title when available
- Follow redirects.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | no_corresponding_group_error.patch | 1.32 KB | ian-dev |
Issue fork easy_breadcrumb-3415146
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
greg boggsThat's a tough one. EB just calls getRouteName on the current page.
As a test, maybe Current Page Crumb will work for your site? It's a super duper simple version of Easy Breadcrumb that just sets the current page title as the crumb.
https://www.drupal.org/project/current_page_crumb
Comment #3
david.houlder commentedSee
https://git.drupalcode.org/project/easy_breadcrumb/-/blob/2.0.4/src/Easy...
I commented out the first $title assignment
and it works now. Since that value of $title is never used, I suspect this may be a fix, at least for my case. I'm not familiar enough with the Drupal API to guess what was intended here.
Comment #4
greg boggsThat's the line of code that gets the title of the page for use in the crumb. Without it, you're getting the fallback title or entity label for each route.
Comment #5
greg boggsI believe if you turn off "use page title" that section of code won't run.
Comment #6
david.houlder commentedI don't think so. Have a look at the code. $title is overwritten by $entity->label(); in all cases. The result of getTitleString() is never used here, and none of its arguments are passed by reference.
Comment #7
greg boggswell, that's certainly a bug! Thanks for finding it. That line has been updated so many times, it's difficult to keep track of. It's definitely NOT supposed to be replaced by the entity label.
Comment #8
greg boggsOh, I see what happened, you should use the latest version of the module.
https://www.drupal.org/project/easy_breadcrumb/releases/2.x-dev
Comment #9
david.houlder commentedHi Greg. With 2.x-dev I still get
My use case is not particularly weird. The URLs that cause problems are generated by a taxonomy view block. There are bound to be other sites affected by this.
See the live site https://xyonline.net/ (running easy_breadcrumb 2.0.2). There's a Topics menu in the left sidebar, which is provided by a taxonomy view block. The URLs in that topic list are the ones that cause problems in easy_breadcrumb > 2.0.3.
To make this work I've patched 2.x-dev (see below). There's arguably a bit too much code in the try block, but this gets me out of trouble. I don't know if you want to pursue this further, but I've already spent way too much time on this, and I'm going to use my patched version to get the site to a state where I can migrate to Drupal 10, unless you have a better idea.
cheers
David
Comment #10
greg boggsHrm, this looks like a core bug, but I am not sure which one. Can you try this patch to see if it gives us a better error to go off?
https://www.drupal.org/project/drupal/issues/3308418
Comment #11
greg boggsIf we can't fix it, I am happy to commit the try {} catch approach with two small updates:
1. Wrap the entire function block in try catch, this makes it so the catch is at the end of the function and not the middle.
2. Add a code comment explaining why we are catching this error.
Comment #12
david.houlder commentedThat's already done in
https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/lib/Drupal/C...
and the offending url is already reported in the error string: UnexpectedValueException: base:category/article-content/growing has no corresponding route. in Drupal\Core\Url->getRouteName() (line 567 of core/lib/Drupal/Core/Url.php).
I think that's bad idea. You want the try to wrap as little code as possible because we're only interested in the UnexpectedValueException from getRouteName(). Wrapping the entire block in a try would catch the exception from everything, which would obscure unanticipated UnexpectedValueExceptions from other things which should be debugged and fixed.
Comment #13
greg boggsBetter that this module never throws an exception in a live website, it's just breadcrumbs. Don't want it white screening a website ever.
Comment #14
david.houlder commentedSure, but in that case, why isn't it wrapped in a try…catch already? I would argue that if the code is so poorly behaved or understood that you have to do that, you've got some significant problems with code quality.
Besides, I'm using the code after my try…catch to set $title appropriately, and on top of that, keeping the try block small makes the code easier to understand, as it limits the scope of calls that are likely to throw the exception. It also means you don't need a comment in the catch block many lines distant from the function call describing what's going on.
As I said before, I have spent way too much time on this already, and I am unlikely to be the only one who runs into this problem. I am going ahead with my patched version of 2.0.5 or 2.x-dev. You guys know this code way better than me, and are in a much better position to diagnose any underlying issue.
Thanks for your time anyway.
cheers
David
Comment #15
greg boggsWould you mind posting the rest of the code for the catch so I can include it when I merge your work to the module?
Comment #16
david.houlder commentedSure, no worries.
easy_breadcrumb/src/TitleResolver.php
and the rest is unchanged.
Comment #17
greg boggsAhh cool, thanks David. I thought there was a bit in the catch to set a title, but that makes sense. I'll get it merged and publish a 2.0.6 for you.
Comment #18
david.houlder commentedOK, thanks Greg. I will wait for 2.0.6.
Comment #19
david.houlder commentedFor what it's worth, those problematic paths are URL aliases for taxonomy terms. e.g. in /taxonomy/term/260/edit I see
Name: Calls for Papers
URL alias: /category/article-content/calls-papers
Comment #20
solideogloria commented2.0.6 has been released. Should this issue be closed?
Comment #21
greg boggsI didn't get this one into 2.0.6, it will be in 2.0.7
Comment #22
greg boggsNeeds a MR created.
Comment #23
ian-dev commentedI'm having the same issue as David. Rolled his solution into a patch as it works for me after testing. Will do a PR later but not sure if that's the best fix long term.
Sorry should have titled it "no_corresponding_route"
Here's a trace of the error. Using drupal group module if that's any help.
Comment #24
greg boggslooks good. Feel encouraged to open an MR.
Comment #27
rollins commentedI opened an MR.
Comment #28
rollins commentedComment #29
spuky commentedlooks good
Comment #31
spuky commented