1

I'm seeing the following error log in New Relic. This error logs very rarely, and comes from adding a product to the cart:

TypeError: Uncaught exception 'TypeError' with message 'Argument 1 passed to Magento\Catalog\Block\Product\ImageBuilder::setProduct() must be an instance of Magento\Catalog\Model\Product, null given, called in /srv/public_html/vendor/author/name/Block/Confirm.php on line 417' in /srv/public_html/vendor/magento/module-catalog/Block/Product/ImageBuilder.php:55

I'm not sure why this error is logging, this is the block of code in question (Confirm.php, Lines 415 - 421):

 public function getImage($product, $imageId, $attributes = [])
 {
    return $this->imageBuilder->setProduct($product)
        ->setImageId($imageId)
        ->setAttributes($attributes)
        ->create();
 }

Does anyone see anything out of the ordinary here, that would cause such an error?

Cheers, Max

  • you could check if it is actually a product. if (!$product instanceof Magento\Catalog\Model\Product) { return false; } – Zankar Sep 17 at 5:26
0

The file vendor/magento/module-catalog/Block/Product/ImageBuilder.php is declared to use strict types(declare(strict_types=1);) since you do not pass a Product but null it throws an TypeError. Long story short - you do not pass a Product to getImage, so check the method call and arguments you pass.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.