Updated to the Dev version recently so that I could apply a patch. Noticed that if I go to URLs that don't exist, I get a 503 Server Error (WDOD) instead of a 404 error. The error in the log is:

Symfony\Component\Routing\Exception\ResourceNotFoundException: No routes found for "/a". in Drupal\Core\Routing\Router->matchRequest() (line 125 of /home/vagrant/sites/solarwindsmsp/docroot/core/lib/Drupal/Core/Routing/Router.php).

This might to be related to using Custom Error pages and having the Global default canonical be set to [current-page:url:absolute].

The trace-back showed the root cause was from the use of Url::createFromRequest($request) in the token_tokens function. These calls should be wrapped in a try / catch with a fallback option and not cause a WSOD.

I found a work around by setting the custom error page nodes to use [site:url] for their canonical values.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cgmonroe created an issue. See original summary.

Berdir’s picture

Status: Active » Needs review
FileSize
3.36 KB

Confirmed, working on a fix and updating tests, but not quite sure how what the best way of getting the path is in case of an exception.

cgmonroe’s picture

Seems like if the path is not a Drupal route it should be the one from the request, e.g. Request::getRequestUri() (path / query only) or Request::getUri() (abs. path).

monnerat’s picture

Patch #2 applied to 8.x-1.2 fixes the problem for me. Thanks.

Adamation’s picture

I'm currently experiencing this issue on a production site.

I can't determine when I first noticed the issue.

sjancich’s picture

I got a variation of this error when installing a new site from a custom install profile. Patch #2 fixed it.

Drupal\Core\ParamConverter\ParamNotConvertedException: The "node" parameter was not converted for the path "/node/{node}" (route name: "entity.node.canonical") in Drupal\Core\ParamConverter\ParamConverterManager->convert() (line 104 of /vagrant/public/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php).

Drupal\Core\ParamConverter\ParamConverterManager->convert(Array) (Line: 45)
Drupal\Core\Routing\Enhancer\ParamConversionEnhancer->enhance(Array, Object) (Line: 259)
Drupal\Core\Routing\Router->applyRouteEnhancers(Array, Object) (Line: 130)
Drupal\Core\Routing\Router->matchRequest(Object) (Line: 479)
Drupal\Core\Url::createFromRequest(Object) (Line: 750)
token_tokens('current-page', Array, Array, Array, Object)
call_user_func_array('token_tokens', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 304)
Drupal\Core\Utility\Token->generate('current-page', Array, Array, Array, Object) (Line: 196)
Drupal\Core\Utility\Token->replace('[current-page:url]', Array, Array) (Line: 48)
Drupal\metatag\MetatagToken->replace('[current-page:url]', Array, Array) (Line: 514)
Drupal\metatag\MetatagManager->generateRawElements(Array, NULL) (Line: 443)
Drupal\metatag\MetatagManager->generateElements(Array, NULL) (Line: 437)
metatag_get_tags_from_route() (Line: 369)
metatag_preprocess_html(Array, 'html', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 139)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 140)
Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 66)
Drupal\Core\Render\BareHtmlPageRenderer->renderBarePage(Array, Object, 'install_page', Array) (Line: 76)
Drupal\Core\ProxyClass\Render\BareHtmlPageRenderer->renderBarePage(Array, Object, 'install_page', Array) (Line: 1040)
install_display_output(Array, Array) (Line: 159)
install_drupal(Object) (Line: 44)

Berdir’s picture

Improved test coverage and also updated the second call to createFromRequest().

@cgmonroe: that's what the patch does, getPathInfo() is getRequestUri(), minus the base path.

  • Berdir committed 70c20db on 8.x-1.x
    Issue #2969344 by Berdir: 503 Server Errors / ResourceNotFoundException...
Berdir’s picture

Status: Needs review » Fixed

I don't know if this is the best fix, but it seems to work and is better than what we have now.

mxh’s picture

Status: Fixed » Needs work

Unfortunately Url::fromUserInput would also throw an exception in case of urls like http://mysite/http://mysite/.

Suggestions:

  • Why not using the request information directly when Url object instantiation fails? or
  • What about using Url::fromRoute('<current>') instead of ::fromUserInput as the comment would imply? Regardless the doc comment seems to be wrong, as the instruction is actually not directly using the <current> route.
// Url::createFromRequest() can fail, e.g. on 404 pages, fall back
// the <current> route.
mxh’s picture

Status: Needs work » Needs review
FileSize
2.18 KB

Not sure.

Berdir’s picture

forgot to update the comment. Problem is that <current> is actually system/404 on a 404 page :)

mxh’s picture

Problem is that is actually system/404 on a 404 page

True, seems that Url::fromUserInput might be the only option we have here then.

Berdir’s picture

Yeah. Can we extend the test coverage to cover this?

Not quite sure if we can trigger your case through a different URL in the existing UrlTest, maybe we could also do it in a kernel test?

mxh’s picture

Added a first try for a kernel test. Maybe there's still some work needed regards consistency: the token replacement on "malformed" paths like /https://drupal.org/ would now result as empty, which is different for "non-malformed" paths where the response is a 404 page (for them, it seems the result would be /).

Status: Needs review » Needs work
mxh’s picture

Seems I'm not able to create a patch with new files. Making a Drupal patch with Git could not help me either :/

mxh’s picture

  • Berdir committed d7e64df on 8.x-1.x authored by mxh
    Issue #2969344 by mxh, Berdir: 503 Server Errors /...
Berdir’s picture

Status: Needs review » Fixed

Thanks, looks good to me.

Status: Fixed » Closed (fixed)

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