Error when added to 404 pages

Created on 26 October 2023, about 1 year ago

Problem/Motivation

If the Views or the Exposed form is added to a 404 page it will return a Error.
The route will not load the 404 page.

Symfony\Component\Routing\Exception\ResourceNotFoundException: No routes found for "/a". in Drupal\Core\Routing\Router->matchRequest()

Steps to reproduce

Includes the Views with Better Exposed Filters on 404 page.

Proposed resolution

Similar issue with the Token module. See: https://www.drupal.org/project/token/issues/2969344 โ†’

Adds a try/catch to the Url::createFromRequest() on getExposedFormActionUrl() in src/Plugin/BetterExposedFiltersWidgetBase.php file.

๐Ÿ› Bug report
Status

Active

Version

6.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ทBrazil adrianopulz Florianรณpolis

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

Merge Requests

Comments & Activities

  • Issue created by @adrianopulz
  • Assigned to Shreya_98
  • Merge request !49Resolve #3396769 "Error when added" โ†’ (Closed) created by Unnamed author
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shreya_98

    Hi @adrianopulz,
    I have fixed this issue and also created MR for this issue . please replace The 'internal:/' URL is a reference to the internal path '/', which typically represents the homepage of your Drupal site. In other words, it's setting the fallback URL to the site's homepage.

    Thank you!

  • ๐Ÿ‡ง๐Ÿ‡ทBrazil adrianopulz Florianรณpolis

    Thanks for your fork @shreya_th!

    The problem is for URLs created from the Request, URLs from the route will not be a problem. You added try/catch to the URL created from the route when the display['display_options']['path'] is set. We need the fallback only in the createFromRequest() call.

    I've added a patch with the change example. I don't think we need to change the block of code using the UrlFromRoute.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    What about other system paths?

  • Status changed to Postponed: needs info 8 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    That snippet of code has been removed in another fix. Can you confirm this is still an issue.

  • Status changed to Closed: outdated 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Johan den Hollander

    Hate to be reopening this issue, but the issue is still there using the latest 7.x release.

    We worked around the issue for now by modifying the code to be as follows:

    use Symfony\Component\Routing\Exception\ResourceNotFoundException;
    
    protected function getExposedFormActionUrl(FormStateInterface $form_state): Url {
        $request = \Drupal::request();
        try {
          $url = Url::createFromRequest(clone $request);
          $url->setAbsolute();
          return $url;
        }
        catch (ResourceNotFoundException $e) {
          return Url::fromRoute('<front>')->setAbsolute();
        }
      }

    A patch will follow, I expect this code needs some better attention.

  • ๐Ÿ‡จ๐Ÿ‡พCyprus alex.bukach

    Alex Bukach โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !86Handled non-existent routes โ†’ (Open) created by alex.bukach
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡จ๐Ÿ‡พCyprus alex.bukach

    Created MR!86, here's the respective patch.

  • Pipeline finished with Success
    6 months ago
    Total: 229s
    #215069
  • Status changed to Needs work 6 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    MR should be against 7.0.x but letโ€™s add test coverage also

  • Status changed to Postponed: needs info 4 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Could the steps be flushed out.

    I added a view block that's used better exposed filters to 404 page and not getting any error.

    On 10.3

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland idflood

    I've got the same issue. I've defined a global "search" exposed form in block, which is added to the header of the website. Then on all 404 pages it shows the same error.

    I've tried the patch in #12 and it went nicely, even if I'm still using the 6.x version. The patch fixed the issue, at least there is now no more errors.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Still needs step to reproduce fully or going to close out

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    We started seeing this issue recently with better_exposed_filters 6.0.6 after upgrading core

    As with #15, we have an exposed search form in the header block which shows on all pages.

    From our tests so far, the patch in #12 seems to fix the issue, but we will test further.

    I've updated the steps to reproduce.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Letโ€™s open an MR for 7.0.x and add a simple test case

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    Having tested further, it seems like the patch fixes the problem for logged-in users, but not anonymous.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    With this patch included, we observed a strange issue where BEF checkboxes showed 0 instead of the expected markup.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    In our case, this seems to relate to facets, as mentioned in #20

    The mention of better_exposed_filters in the stack trace isn't the root of the problem for us.

    When a facets block appears on a 404 page, it causes problems with URL generation.

    I think that the appropriate fix relates to one of these issues:

    #3291943: When rendering facets on non search page, it throws error instead of 404 on 404 pages โ†’
    ๐Ÿ› ResourceNotFoundException with ajax facets when site running in subfolder Needs review

    In \Drupal\facets\Plugin\Block\FacetBlock::build, if we add a condition to stop the block rendering on 404 pages, the problem goes away.

    @idflood, @alex.bucach, @adrianopulaz, @johan den hollander - do the stack traces you see also mention facets?

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom malcomio

    Even with our patch to facets in place, we encountered this error again, although in a slightly odd scenario that came up via a penetration test, with some special characters in the URL.

    Our search results page is at /search-content - the security scanner managed to trigger this exception at /search-content%22%3bexpr%20268409241%20-%2028291%3b%22?search= (and some other similar URLs).

    When we apply the patch in #12, it addresses the issue.

    The error mentioned in #21 seems to have been happening because we were using an incorrect patch for ๐Ÿ› Links with "Show hierarchy in dropdown" disabled gives "Deprecated function: range(): Passing null to parameter #1" Active

  • Status changed to Needs work 22 days ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany c-logemann Frankfurt/M, Germany

    We have the same problem with global search block on core 10.2.* and better_exposed_filters 6.0.6. and patch #12 solves it. We also have facets but not the problems as reported by @malcomio.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    So is this a facets issue?

    I enabled the bef_test module which has a view with an exposed block.
    I placed the block on every page
    I visited some gibberish url
    Got the 404 page not found and my block just fine.

    7.0.x and 11.1.x

    Sorry if I'm missing something just trying to replicate so I can merge and add test coverage.

Production build 0.71.5 2024