If Focal Point attempts to load an image and the image is not present, this can lead to an InvalidArgumentException being thrown, which breaks site display. Ideally this should just lead to the image not being rendered (as would normally happen for a missing image).

There may be special circumstances that lead to this being an issue on the site I've seen it on. It looks like the image is coming via shortcut module (?), and this happens even when viewing the site's admin interface (which shouldn't be hitting the custom theme, though that's visible below).

Observing this behaviour after clearing cache, and on a dev environment which lacks a local copy of the site media (hence $image->isValid() is not true).

Error displayed is:

The website encountered an unexpected error. Please try again later.Symfony\Component\Validator\Exception\InvalidArgumentException: The file with id = $fid is not an image. in Drupal\focal_point\Controller\FocalPointPreviewController->access() (line 117 of modules/contrib/focal_point/src/Controller/FocalPointPreviewController.php). 
call_user_func_array(Array, Array) (Line: 68)
Drupal\Core\Access\CustomAccessCheck->access(Object, Object, Object)
call_user_func_array(Array, Array) (Line: 159)
Drupal\Core\Access\AccessManager->performCheck('access_check.custom', Object) (Line: 135)
Drupal\Core\Access\AccessManager->check(Object, Object, NULL, ) (Line: 92)
Drupal\Core\Access\AccessManager->checkNamedRoute('focal_point.preview', Array, NULL) (Line: 809)
Drupal\Core\Url->access() (Line: 269)
shortcut_renderable_links() (Line: 392)
shortcut_toolbar()
call_user_func_array('shortcut_toolbar', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('toolbar') (Line: 81)
Drupal\toolbar\Element\Toolbar::preRenderToolbar(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 507)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 86)
__TwigTemplate_370319f7193408b12a6a6181dd4824874cf4f39e1bfbacc823a86b5ab4b1722f->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/custom/example/templates/system/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 666)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
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:

Comments

xurizaemon created an issue. See original summary.

xurizaemon’s picture

xurizaemon’s picture

Status: Active » Needs review

Attached patch will return AccessResult::forbidden() and log a warning, but not throw a site-breaking exception.

xurizaemon’s picture

Updating patch to more closely match what happens in core's ImageStyleDownloadController (use notice not warning, update language).

bleen’s picture

+++ b/src/Controller/FocalPointPreviewController.php
@@ -114,7 +114,11 @@ class FocalPointPreviewController extends ControllerBase {
+      \Drupal::logger('focal_point')

+++ b/src/Controller/FocalPointPreviewController.php
@@ -114,9 +114,10 @@ class FocalPointPreviewController extends ControllerBase {
+      \Drupal::service('logger.factory')

Why are you using logger.factory in one place, but not the other?

bleen’s picture

wait ... are you patching the same file twice?

Something is weird in #4

xurizaemon’s picture

Thanks for taking a look bleen.

Yep, that's a normal output mode of `git diff / git show` with multiple commits, ie if you export with git show 8.x-1.x..8.x-1.x-123_feature

You should find it applies as a normal patch?

In the first revision I'd used Drupal::logger, then switched to the factory usage.

I tend to use that method for patches because it can better preserve history from a feature branch while using patch sharing rather than pull requests, but I can resubmit if you find the patch doesn't work for you?

jcnventura’s picture

Re-rolling #4, to take into account the dependency injection changes.

I came across this issue while trying to figure out why an InvalidArgumentException is thrown when trying to edit a node that uses the focal point widget. Unfortunately, the patch did nothing for me, and I eventually traced it to a problem elsewhere.

In any case, I fixed it a bit.

ratvas’s picture

Adding dependency injection and cover-up access method as well.
The patch is re-rolled against 2.0.2.

tim-diels’s picture

Version: 8.x-1.0-beta6 » 2.x-dev
Status: Needs review » Reviewed & tested by the community

We were experiencing the same issues as described and latest patch from #9 solves issue for us. Thanks!

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

  • Rajeshreeputra committed c2464787 on 2.x
    Issue #2997372 by Rajeshreeputra, xurizaemon, jcnventura, ratvas, bleen...
rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

Merged, release to follow shortly!

Status: Fixed » Closed (fixed)

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