TypeError in createPdfImageEntity and createThumbnailFileEntity

Created on 25 September 2024, about 2 months ago

Problem/Motivation

TypeError :
Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager::createPdfImageEntity():
Argument #5 ($imageFileInfo) must be of type array, null given, called in /web/modules/contrib/media_pdf_thumbnail/src/Manager/MediaPdfThumbnailImageManager.php on line 156 dans Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager->createPdfImageEntity() (ligne 292 de /web/modules/contrib/media_pdf_thumbnail/src/Manager/MediaPdfThumbnailImageManager.php).

TypeError :
Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager::createThumbnailFileEntity():
Argument #1 ($fileUri) must be of type string, null given, called in /web/modules/contrib/media_pdf_thumbnail/src/Manager/MediaPdfThumbnailImageManager.php on line 156 dans Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImageManager->createThumbnailFileEntity() (ligne 342 de /web/modules/contrib/media_pdf_thumbnail/src/Manager/MediaPdfThumbnailImageManager.php).

File /src/Manager/MediaPdfThumbnailImageManager.php line 156 :

$pdfImage = $this->createPdfImageEntity($entity, $fileFieldName, $fileEntity, $page, $this->createThumbnailFileEntity($this->generatePdfImage($fileEntity, $imageFormat, $page)));

Function generatePdfImage allowed to return NULL but function createThumbnailFileEntity expects STRING.

Function createThumbnailFileEntity allowed to return NULL but function createPdfImageEntity expects ARRAY.

Proposed resolution

Change function declaration :

protected function createThumbnailFileEntity(string $fileUri) {

to

protected function createThumbnailFileEntity(?string $fileUri) {

and

protected function createPdfImageEntity(EntityInterface $entity, string $fieldName, EntityInterface $fileEntity, string | int $page, array $imageFileInfo): ?array {

to

protected function createPdfImageEntity(EntityInterface $entity, string $fieldName, EntityInterface $fileEntity, string | int $page, ?array $imageFileInfo): ?array {
🐛 Bug report
Status

Active

Version

6.1

Component

Code

Created by

🇫🇷France slayne40

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @slayne40
  • 🇫🇷France rubberg

    Hi @slayne40 ,

    Could you please add steps to reproduce the error you encountered?

    I tried to review your patch but was not able to get the error.

    Tested on Drupal 10.3.5 and Media PDF Thumbnail 6.1.1 (php 8.2.20)

    Thank you.

  • 🇮🇹Italy finex

    Hi, I've had the same error followed by another (which is probably the cause):

    attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/426

    It's an error on the server imagemagick policy.

    I suggest to catch the error and display a message to inform the user to update the imagemagick settings.

  • Hi,

    I'm able to reproduce the error with the very specific following configuration:

    • On a dev environment, I imported a dump of the prod database
    • Since I'm not interested in getting all production uploaded media files, I did not get an archive of all of them. Just got the latest ones.
    • I'm now running a dev environment with references to uploaded PDF files stored in the database but without the actual files stored in the upload directory.

    When launching cron, I'm facing the typeError issue because of the missing files. The process fails in MediaPdfTumbnailImagickManager::generateImageFromPdf() which raises an exception due to the missing file, writes a log entry about it
    and then returns NULL. Because of this NULL, the remaining part of the generation process runs into the typeError error.

    I agree with @slayne40, createThumbnailFileEntity should be allowed to accept NULL to prevent failure and WSOD.

    Tested the #2 patch, it's working.

Production build 0.71.5 2024