cloudinary / cloudinary_wordpress

Cloudinary's WordPress plugin
GNU General Public License v2.0
39 stars 28 forks source link

500 error when saving page #941

Open nomadic-energy-dev opened 6 months ago

nomadic-energy-dev commented 6 months ago

Saving some pages with the Cloudinary plugin installed causes the following error: Undefined array key "full" {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key \"full\" at /home/devadmin/sites/test/public/public/content/plugins/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php:874

It appears that an image has been cropped, but there's no "full" meta data for the width, so the plugin throws an exception and exits.

Additional context

cloudinary-report-1708942593.json

nomadic-energy-dev commented 6 months ago

Additional info from local debugging: this is the unserialized meta data from one of the images causing the error:

This is the raw unserialized meta data from the database:

Array ( [width] => 100 [height] => 100 [file] => Website-Icons-68.svg [sizes] => Array ( [thumbnail] => Array ( [width] => 150 [height] => 150 [crop] => 1 [file] => Website-Icons-68.svg [mime-type] => image/svg+xml )

        [medium] => Array
            (
                [width] => 300
                [height] => 300
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [medium_large] => Array
            (
                [width] => 768
                [height] => 0
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [large] => Array
            (
                [width] => 1024
                [height] => 1024
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [1536x1536] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [2048x2048] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [woocommerce_thumbnail] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
                [uncropped] => 
            )

        [woocommerce_single] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [woocommerce_gallery_thumbnail] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [shop_catalog] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [shop_single] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [shop_thumbnail] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

        [dgwt-wcas-product-suggestion] => Array
            (
                [width] => 
                [height] => 
                [crop] => 
                [file] => Website-Icons-68.svg
                [mime-type] => image/svg+xml
            )

    )

)

This is the var_dump of the meta the plugin is using at the point of exception - you can see the width and height is missing:

array(4) { ["width"]=> int(0) ["height"]=> int(0) ["file"]=> string(20) "Website-Icons-68.svg" ["sizes"]=> array(10) { ["woocommerce_thumbnail"]=> array(6) { ["width"]=> bool(false) ["height"]=> bool(false) ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" ["uncropped"]=> bool(false) } ["woocommerce_gallery_thumbnail"]=> array(5) { ["width"]=> bool(false) ["height"]=> bool(false) ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["woocommerce_single"]=> array(5) { ["width"]=> bool(false) ["height"]=> bool(false) ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["dgwt-wcas-product-suggestion"]=> array(5) { ["width"]=> bool(false) ["height"]=> bool(false) ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["thumbnail"]=> array(5) { ["width"]=> string(3) "150" ["height"]=> string(3) "150" ["crop"]=> string(1) "1" ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["medium"]=> array(5) { ["width"]=> string(3) "300" ["height"]=> string(3) "300" ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["medium_large"]=> array(5) { ["width"]=> string(3) "768" ["height"]=> string(1) "0" ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["large"]=> array(5) { ["width"]=> string(4) "1024" ["height"]=> string(4) "1024" ["crop"]=> bool(false) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["1536x1536"]=> array(5) { ["width"]=> int(1536) ["height"]=> int(1536) ["crop"]=> int(0) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } ["2048x2048"]=> array(5) { ["width"]=> int(2048) ["height"]=> int(2048) ["crop"]=> int(0) ["file"]=> string(20) "Website-Icons-68.svg" ["mime-type"]=> string(13) "image/svg+xml" } } }

nomadic-energy-dev commented 6 months ago

This was directly related to SVG support in Wordpress. The SVG plug we were using (SVG Support - most popular!) was not setting the widths for SVGs where WP's attachment functions were not.

We installed a different plugin (Safe SVG) and the problem is solved.

I think there is still a bug here where if this does happen, it would be useful to set a default or to throw an error more helpful to customers to find a solution rather than spending time debugging core WP attachment handling and Cloudinary's plugin code.

Vdeub-cloudinary commented 6 months ago

Hi @nomadic-energy-dev, Is it only a specific SVG that was throwing the error? Would you have the SVG in question so I can have a look? Could you also share if SVG Support under the Cloudinary Image settings was enabled?. Thanks!

nomadic-energy-dev commented 6 months ago

Thanks - enabling svg support resolved this. Could we improve error handling to catch and report a more useful error in this case?

Vdeub-cloudinary commented 6 months ago

@nomadic-energy-dev awesome news! Glad it fixed the issue. I'll share this with our development team in case there is anything they can do.