Describe the bug
Hey, I think I've found an issue here.
Where an image 404s, it appears to throw an exception which causes a 500 template error which I don't think is the right thing to do.
I think this was thrown where a placeholder image was generated, e.g. with a query like so:
{% set fallbackImage = craft.imageOptimize.createOptimizedImages(
desktopImage,
[
{
'width': desktopImage.width > 1920 ? 1920 : desktopImage.width,
'format': 'jpg',
},
],
true,
) %}
The source asset is genuinely missing on the volume, however, the imgix transforms are still loading, so where placeholders are not generated with false in the createOptimizedImages 3rd param, this does not 500 error
To reproduce
Steps to reproduce the behaviour:
- Use craft-imageoptimize with imgix
- Try render an asset where the source file is missing on the volume, in my case using a Fortrabbit Object Storage Volume
- See error message:
GuzzleHttp\Exception\ClientException: Client error: GET https://project-name-stage.objects.eu2.frbit.com/path/image.jpg resulted in a 404 Not Found response in /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111
Stack trace:
#0 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}()
#4 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Promise\TaskQueue->run(true)
#5 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /srv/app/project-name-stage/htdocs/cms/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /srv/app/project-name-stage/htdocs/cms/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
#10 /srv/app/project-name-stage/htdocs/cms/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php(470): Aws\AwsClient->execute(Object(Aws\Command))
#11 /srv/app/project-name-stage/htdocs/cms/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php(219): League\Flysystem\AwsS3V3\AwsS3V3Adapter->readObject('path/image...', true)
#12 /srv/app/project-name-stage/htdocs/cms/vendor/league/flysystem/src/Filesystem.php(81): League\Flysystem\AwsS3V3\AwsS3V3Adapter->readStream('path/image...')
#13 /srv/app/project-name-stage/htdocs/cms/vendor/craftcms/flysystem/src/base/FlysystemFs.php(204): League\Flysystem\Filesystem->readStream('path/image...')
#14 /srv/app/project-name-stage/htdocs/cms/vendor/craftcms/cms/src/models/Volume.php(670): craft\flysystem\base\FlysystemFs->getFileStream('path/image...')
#15 /srv/app/project-name-stage/htdocs/cms/vendor/craftcms/cms/src/helpers/Assets.php(866): craft\models\Volume->getFileStream('path/image...')
#16 /srv/app/project-name-stage/htdocs/cms/vendor/craftcms/cms/src/helpers/ImageTransforms.php(179): craft\helpers\Assets::downloadFile(Object(craft\models\Volume), 'path/image...', '/srv/app/project...')
#17 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/services/Placeholder.php(248): craft\helpers\ImageTransforms::getLocalImageSource(Object(craft\elements\Asset))
#18 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/services/Placeholder.php(229): nystudio107\imageoptimize\services\Placeholder->createImageFromAsset(Object(craft\elements\Asset), 300, 161, 75, Array)
#19 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/services/OptimizedImages.php(475): nystudio107\imageoptimize\services\Placeholder->createTempPlaceholderImage(Object(craft\elements\Asset), 1.8571428571429, Array)
#20 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/services/OptimizedImages.php(593): nystudio107\imageoptimize\services\OptimizedImages->generatePlaceholders(Object(craft\elements\Asset), Object(nystudio107\imageoptimize\models\OptimizedImage), 1.8571428571429)
#21 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/services/OptimizedImages.php(149): nystudio107\imageoptimize\services\OptimizedImages->addVariantImageToModel(Object(craft\elements\Asset), Object(nystudio107\imageoptimize\models\OptimizedImage), Object(craft\models\ImageTransform), Array, 1.8571428571429)
#22 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/services/OptimizedImages.php(77): nystudio107\imageoptimize\services\OptimizedImages->populateOptimizedImageModel(Object(craft\elements\Asset), Array, Object(nystudio107\imageoptimize\models\OptimizedImage))
#23 /srv/app/project-name-stage/htdocs/cms/vendor/nystudio107/craft-imageoptimize/src/variables/ImageOptimizeVariable.php(89): nystudio107\imageoptimize\services\OptimizedImages->createOptimizedImages(Object(craft\elements\Asset), Array)
#24 /srv/app/project-name-stage/htdocs/cms/vendor/twig/twig/src/Extension/CoreExtension.php(1861): nystudio107\imageoptimize\variables\ImageOptimizeVariable->createOptimizedImages(Object(craft\elements\Asset), Array, true)
#25 /srv/app/project-name-stage/htdocs/cms/vendor/craftcms/cms/src/helpers/Template.php(148): Twig\Extension\CoreExtension::getAttribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(nystudio107\imageoptimize\variables\ImageOptimizeVariable), 'createOptimized...', Array, 'method', false, false, false, 87)
#26 /srv/app/project-name-stage/htdocs/cms/storage/runtime/compiled_templates/6b/6b62e6339f34852d0eee07e73a3bbc9a.php(131): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(nystudio107\imageoptimize\variables\ImageOptimizeVariable), 'createOptimized...', Array, 'method', false, false, false, 87)
Expected behaviour
no 500 error
Screenshots
If applicable, add screenshots to help explain your problem.
Versions
- Plugin version: "nystudio107/craft-imageoptimize": "^5.0.7",
- Craft version: "craftcms/cms": "5.6.7",
Describe the bug
Hey, I think I've found an issue here.
Where an image 404s, it appears to throw an exception which causes a 500 template error which I don't think is the right thing to do.
I think this was thrown where a placeholder image was generated, e.g. with a query like so:
{% set fallbackImage = craft.imageOptimize.createOptimizedImages( desktopImage, [ { 'width': desktopImage.width > 1920 ? 1920 : desktopImage.width, 'format': 'jpg', }, ], true, ) %}The source asset is genuinely missing on the volume, however, the imgix transforms are still loading, so where placeholders are not generated with
falsein thecreateOptimizedImages3rd param, this does not 500 errorTo reproduce
Steps to reproduce the behaviour:
Expected behaviour
no 500 error
Screenshots
If applicable, add screenshots to help explain your problem.
Versions