If you have images in wysiwyg you will get the following error
Error: Call to a member function getMetadata() on null in Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit->parseFileViaIdentify() (line 952)

Comments

Anas_maw created an issue. See original summary.

anas_maw’s picture

Status: Active » Needs review
StatusFileSize
new736 bytes

This patch solve the issue

mondrake’s picture

Thank you @Anas_maw!

The proposed change makes sense - as it makes generally sense to check if an object exists before trying to invoke one of its methods. However, that will mean that the Image object will not be valid afterwards.

Can you elaborate a bit as to why at that point in code the file metadata manager service cannot set the URI for $this->getSource()?

mondrake’s picture

mondrake’s picture

Status: Needs review » Needs work
michael.chadwick’s picture

I am hitting the same error but I do not believe it is specifically related to WYSIWYG. From my investigation it looks like it has something to do with Media passing ImageMagick the no-thumbnail.png or the generic.png at a relative path before the image itself.

My scenario:

I have Drupal core (8.5.6) Media enabled and 2 media types configured from from that Image and Document. I get the error reported above when trying to create either of the media types via their default media add forms.

Sticking a breakpoint on line 1212 shows me that ImageMagick is passed '/no-thumbnail.png' or the '/generic.png' paths before the actual image from the file upload field. These files don't seem to be getting picked up as part of the fileMetadataManager process. Assuming due to their relative paths. When you see the actual image that was uploaded go through the same process it has an absolute path to it in the files folder and works as expected.

The no-thumbnail.png was due to me having Queue thumbnail downloads checkbox checked on my Image media entity. Turning that off will allow me to save my Image media. The problem with my Document media entity which has a file field with .pdf extensions. ImageMagick is having the generic.png passed to it on a file upload. As far as I can see there is no way to prevent this. Meaning my documents will always fail to upload.

When I apply the #2 patch I am able to save both media types. In response #3 I believe a check here is valid, probably one that would gracefully fail if the image is not accessible for whatever reason.

maximpodorov’s picture

Status: Needs work » Needs review
StatusFileSize
new756 bytes

Re-roll.

mondrake’s picture

Status: Needs review » Needs work

Can anybody with the issue please enable some debugging:

  • tick the 'Display debugging information' checkbox
  • add a -debug All argument in the 'Prepend arguments' textbox

this will capture an actually very verbose log of all the internal operations performed by the executable (http://www.imagemagick.org/script/command-line-options.php#debug) in the dblog. Then post the results.

bdanin’s picture

The error output from before the patch in #7 is below. The patch in #7 allowed uploads in entity-browser to work again, thanks!

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getMetadata() on null in Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit->parseFileViaIdentify() (line 1239 of modules/contrib/imagemagick/src/Plugin/ImageToolkit/ImagemagickToolkit.php).

Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit->parseFileViaIdentify() (Line: 1221)
Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit->parseFile() (Line: 53)
Drupal\Core\Image\Image->__construct(Object, '/generic.png') (Line: 85)
Drupal\Core\Image\ImageFactory->get('/generic.png') (Line: 321)
Drupal\image\Plugin\Field\FieldType\ImageItem->preSave() (Line: 233)
Drupal\Core\Field\FieldItemList->delegateMethod('preSave') (Line: 191)
Drupal\Core\Field\FieldItemList->preSave() (Line: 873)
Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('preSave', Object) (Line: 823)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('presave', Object) (Line: 492)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 692)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 446)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 29)
Drupal\media\MediaStorage->save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase->save() (Line: 195)
Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget\MediaEntityDropzoneJsEbWidget->submit(Array, Array, Object) (Line: 225)
Drupal\entity_browser\Form\EntityBrowserForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 590)
Drupal\Core\Form\FormBuilder->processForm('entity_browser_media_image_browser_form', Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder->buildForm('entity_browser_media_image_browser_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
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: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
mondrake’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
Assigned: Unassigned » mondrake
Issue tags: -Needs steps to reproduce

Thank you all for the input, I could reproduce the error.

1. I find *very* strange that the image system tries to open an image file located at '/generic.png', that would mean it would be at the root at the file system - unlikely it will be there. Probably some part of the entire file path is not passed in in the ImageFactory->get() call. But that is another issue.

2. Patch here is good, as it ensures the Image object is invalid. We are clearly missing a basic test to check that an attemp to load a missing file does not fatal out.

Working on adding an appropriate test.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new1.65 KB
new741 bytes

Adding tests and enhancing a bit the logic.

Status: Needs review » Needs work

The last submitted patch, 11: 2936392-11-test-only.patch, failed testing. View results

mondrake’s picture

  • mondrake committed 5c2c6d9 on 8.x-3.x
    Issue #2936392 by mondrake, Anas_maw, maximpodorov, michael.chadwick,...
mondrake’s picture

Status: Needs work » Patch (to be ported)

Committed and pushed to 8.x-3.x, working on backport to 8.x-2.x

mondrake’s picture

Version: 8.x-3.x-dev » 8.x-2.x-dev
mondrake’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.23 KB
new2.77 KB

The last submitted patch, 17: 2936392-17-test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 17: 2936392-17.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new514 bytes
new2.78 KB

  • mondrake committed febac1e on 8.x-2.x
    Issue #2936392 by mondrake, Anas_maw, maximpodorov, michael.chadwick,...
mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs review » Fixed

Committed backport and pushed to 8.x-2.x

Status: Fixed » Closed (fixed)

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