Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No proper error handling in validateUpload of Isotope/Widget/MediaManager #2468

Closed
chberger opened this issue Jun 24, 2023 · 3 comments
Closed
Labels
Milestone

Comments

@chberger
Copy link

I'm facing an issue where I cannot upload product pictures. Even in the system log I can't find any hint pointing to the root cause. The only thing I'm getting is a CRITICAL: Uncaught PHP Exception ErrorException which tells me that the Isotope\Widget\MediaManager class tries to access an array at an undefined position:

[2023-06-24T11:36:47.450658+02:00] request.CRITICAL: Uncaught PHP Exception ErrorException: "Warning: Undefined array key 0" at /var/www/vhosts/#########/shop/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Widget/MediaManager.php line 174 {"exception":"[object] (ErrorException(code: 0): Warning: Undefined array key 0 at /var/www/vhosts/#########//shop/vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Widget/MediaManager.php:174)"} []

The relevant implementation part looks like this:

        $varInput = '';

        try {
            $varInput = $objUploader->uploadTo($uploadFolder);
        } catch (\Exception $e) {
            $this->addError($e->getMessage());
        }

        if ($objUploader->hasError()) {
            $messages = System::getContainer()->get('session')->getFlashBag()->peek('contao_be_error');

            if (\is_array($messages)) {
                foreach ($messages as $strError) {
                    $this->addError($strError);
                }
            }
        }

        Message::reset();

        if (!\is_array($varInput) || empty($varInput)) {
            $this->addError($GLOBALS['TL_LANG']['MSC']['mmUnknownError']);
        }

        return $varInput[0];
    }

I guess in my case the $varInput isn't an array cause something goes wrong in $varInput = $objUploader->uploadTo($uploadFolder);. Thus it shows that generic error message defined by $GLOBALS['TL_LANG']['MSC']['mmUnknownError']. However, after that the code still tries to access the first position of $varInput which is obviously not working.

Overall, I guess it would be helpful if that caught exception would be logged somehow. Otherwise I have no chance to identify the root cause at all.

Contao: 4.13.25
Isotope: 2.8.14
PHP: 8.1.19

@chberger
Copy link
Author

Ok, I've investigated it further. The Contao\Messages are not being propagated properly, because this line is not working anymore:

$messages = System::getContainer()->get('session')->getFlashBag()->peek('contao_be_error');

Based on the contao core code, this should be like:

$messages = System::getContainer()->get('request_stack')->getSession()->getFlashBag()->get('contao.BE.error');

After that, the error messages defined in $objUploader->uploadTo($uploadFolder) pop up at the backend (frontend) as expected.

Anyway, I guess you should still handle that array access in the return statement though.

@aschempp
Copy link
Member

Sounds related to #2472

ameotoko added a commit to ameotoko/isotope-core that referenced this issue Oct 19, 2024
@aschempp aschempp added the bug label Oct 23, 2024
@aschempp aschempp added this to the 2.9.2 milestone Oct 23, 2024
@aschempp
Copy link
Member

Fixed in #2472

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants