Problem/Motivation

I updated an image in the Dam and then synced with Drupal. On a page using that media, I'm getting WSOD and this error in the logs:
TypeError: Drupal\acquia_dam\EmbedCodeUrlBuilder::calculateScaleDimensions(): Argument #1 ($original_dimension) must be of type int, null given, called in /var/www/html/docroot/modules/contrib/acquia_dam/src/EmbedCodeUrlBuilder.php on line 146 in Drupal\acquia_dam\EmbedCodeUrlBuilder::calculateScaleDimensions() (line 175 of /var/www/html/docroot/modules/contrib/acquia_dam/src/EmbedCodeUrlBuilder.php).

Steps to reproduce

Working on steps to reproduce.

I'm using version 1.1.0-beta5 on Drupal 10.4.3, php 8.3.15.

I see that there were changes to this code in https://www.drupal.org/project/acquia_dam/issues/3340734, but I'm not sure yet if that's related.

Comments

capysara created an issue. See original summary.

capysara’s picture

I tried the Sync Metadata from /admin/content/media again, and this time it seemed to fix it. Is it possible that the first time I tried it there wasn't enough time between updating in Dam and trying to sync in Drupal? If that's the case, is there any way to make it fail more gracefully?

ibullock’s picture

Also experienced this issue today on a production site. Thanks @capysara for the workaround!

vipin.mittal18’s picture

Hello @capysara, Could you please outline the exact steps to reproduce the issue?

dan612’s picture

I think this boils down to the image dimensions being missing in the DAM for the source image and an image style that needs to scale is being used. I was experiencing this issue and worked through the stack trace:

"Drupal\acquia_dam\EmbedCodeUrlBuilder::calculateScaleDimensions(): Argument #1 ($original_dimension) must be of type int, null given"

This is being called from Drupal\acquia_dam\EmbedCodeUrlBuilder::mapImageEffects. There is a switch statement to handle various different image effects in mapImageEffects. I am using scale and crop on the image style which is failing, so the following code is being run:

        case 'image_scale_and_crop':
          $values['crop'] = 'yes';
          $values['k'] = $anchor_mapping[$effect['data']['anchor']] ?? 'c';
          $values['w'] = self::calculateScaleDimensions(
            $image_properties['width'],
            self::getDimensionValue($effect['data']['width']),
            TRUE
          );
          $values['h'] = self::calculateScaleDimensions(
            $image_properties['height'],
            self::getDimensionValue($effect['data']['height']),
            TRUE
          );
          break;

The args being passed to calculateScaleDimensions are null, at least for these:

$image_properties['width'],
$image_properties['height'],

$image_properties are passed into the mapImageEffects method, so that means $image_properties value is created in a different location. That location is Drupal\acquia_dam\StreamWrapper\AcquiaDamStreamWrapper->loadAsset. When the following line is run:
$asset_data = $this->getDamClient()->getAsset($this->assetId, $this->versionId);

They are null:
image of missing image properties

When i look in the DAM, these values are missing in the file data:
picture of missing data in the dam

I am not sure what would cause those values to be missing in the DAM, or the best way to update them for that matter.

In terms of failing more gracefully...im not really sure best approach because if it cannot properly apply the image style then it seems like it should hard fail - if we default to "original image" or something if the dimensions are not found, that could be misleading to users who think perhaps the issue is with their entity type display configurations.

vishalkhode’s picture

I've to verified and not seeing any error with 1.1.1. Looks like this is already fixed as part of #3500418: TypeError on EmbedCodeUrlBuilder on new revision update for an existing asset/image on Acquia DAM and released in 1.1.1. Hence, closing.