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)
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | focal_point-2997372-deny_access_dont_throw_exception_if_file_missing-9.patch | 3.55 KB | ratvas |
| #8 | focal_point-2997372-deny_access_dont_throw_exception_if_file_missing-8.patch | 824 bytes | jcnventura |
| #8 | interdiff_2_8.txt | 715 bytes | jcnventura |
Issue fork focal_point-2997372
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
xurizaemonComment #3
xurizaemonAttached patch will return AccessResult::forbidden() and log a warning, but not throw a site-breaking exception.
Comment #4
xurizaemonUpdating patch to more closely match what happens in core's ImageStyleDownloadController (use notice not warning, update language).
Comment #5
bleen commentedWhy are you using logger.factory in one place, but not the other?
Comment #6
bleen commentedwait ... are you patching the same file twice?
Something is weird in #4
Comment #7
xurizaemonThanks 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_featureYou 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?
Comment #8
jcnventuraRe-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.
Comment #9
ratvas commentedAdding dependency injection and cover-up access method as well.
The patch is re-rolled against 2.0.2.
Comment #10
tim-dielsWe were experiencing the same issues as described and latest patch from #9 solves issue for us. Thanks!
Comment #14
rajeshreeputraMerged, release to follow shortly!