Problem/Motivation

The following error has been showing in error logs:

php-error ded-15106 [20-Jan-2021 22:56:13 UTC] TypeError: Argument 3 passed to Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::__construct() must be an instance of Exception or null, array given, called in REDACTED/fast_404/src/Fast404.php on line 214 in REDACTED/vendor/symfony/http-kernel/Exception/ServiceUnavailableHttpException.php on line 25 #0 REDACTED/fast_404/src/Fast404.php(214): Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException->__construct(3, 'The requested U...', Array)

Proposed resolution

Use the $this->t function for the exception message:

throw new ServiceUnavailableHttpException(3, $this->t('The requested URL "@path" was not found on this server. Try again shortly.', ['@path' => $this->request->getPathInfo()]));

Issue fork fast_404-3194034

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

PCate created an issue. See original summary.

PCate’s picture

Status: Active » Needs review
gg4’s picture

IIRC, not translating the exception is intentional. #2055851: Remove translation of exception messages

PCate’s picture

IIRC, not translating the exception is intentional.

@bonus in that case should we just do a string concatenation with UrlHelper::stripDangerousProtocols() for the path variable?

Something like:
throw new ServiceUnavailableHttpException(3, 'The requested URL "' . UrlHelper::stripDangerousProtocols($this->request->getPathInfo()) . '" was not found on this server. Try again shortly.'); ?

PCate’s picture

Changes as patch attached.

Kristen Pol’s picture

Thanks for the issue, patches, and review!

@PCate Could you please add any specific steps to reproduce this?

Kristen Pol’s picture

Also, the issue summary needs updating as the approach changed.

azinck’s picture

I agree this is needed. +1 for the approach in #6.

To reproduce this error you need to have code that calls \Drupal\fast404\Fast404::response() without passing TRUE as an argument. This appears to only happen in fast404_preboot(), so to see this you probably have to be using the advanced installation which entails modifying your settings.php to call fast404_preboot(). If you've done that, then you will hit this error every time fast404 returns a 404.

carsoncho’s picture

Uploading patch that resolves this for the 3.x branch.

emircanerkul made their first commit to this issue’s fork.