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

Missing variable outside CATCH causing a double-fault in Renderer.php #27009

Closed
HeiderSati opened this issue Feb 25, 2020 · 6 comments · Fixed by #27026
Closed

Missing variable outside CATCH causing a double-fault in Renderer.php #27009

HeiderSati opened this issue Feb 25, 2020 · 6 comments · Fixed by #27026
Assignees
Labels
Area: Frontend Award: bug fix Component: Theme Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Reported on 2.3.4 Indicates original Magento version for the Issue report.

Comments

@HeiderSati
Copy link

OK

Preconditions (*)

  1. Magento 2.3.4
  2. MacBook Pro (OSX Catalina)
  3. -and- Linux (Ubuntu)

Steps to reproduce (*)

  1. Create a new Theme, with web/css folder empty inside.
  2. Create your default.xml and catalog_product_view.xml
  3. (Actually, you don't need to worry about re-producing this issue, I attach where exactly the bug is in your code, if you read my notes, you should see that it would fail causing blank-pages or errors sometimes due to double-fault), please see below:

Expected result (*)

  1. All pages to be rendered or errors reported in the log files. (standard)

Actual result (*)

  1. getting an error in: vendor/magento/framework/View/Page/Config/Renderer.php file with missing variable of $template.

  2. The issue is to do with the following code (line 429) on the above file, I attach the function below:

    protected function renderAssetHtml(\Magento\Framework\View\Asset\PropertyGroup $group)
    {
    $assets = $this->processMerge($group->getAll(), $group);
    $attributes = $this->getGroupAttributes($group);

     $template = "";
    
     $result = '';
     try {
         /** @var $asset \Magento\Framework\View\Asset\AssetInterface */
         foreach ($assets as $asset) {
             $template = $this->getAssetTemplate(
                 $group->getProperty(GroupedCollection::PROPERTY_CONTENT_TYPE),
                 $this->addDefaultAttributes($this->getAssetContentType($asset), $attributes)
             );
             $result .= sprintf($template, $asset->getUrl());
         }
     } catch (LocalizedException $e) {
         $this->logger->critical($e);
         $result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']));
     }
     return $result;
    

    }


The issue is that in this code, there is an exception occurring (which is fine/expected), however, inside the catch notice that there is a $template variable being referenced and PHP is throwing the error saying $template does not exists.

This is because $template only exists inside the foreach {} block and would not be accessible from the catch {} block, this causes Magento to render a blank page or come out with an error inside the catch which is a double-fault.

The solution is to add just before the try {} block the following:

 $template = "";

this should fix the issue, I already fixed it on mine and now Magento-2 is working better.

I hope this helps.

Regards
Heider

@m2-assistant
Copy link

m2-assistant bot commented Feb 25, 2020

Hi @HeiderSati. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@HeiderSati do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Feb 25, 2020
@HeiderSati
Copy link
Author

I confirm all the above, can't tick any of the confirmation-boxes, not sure why (using Safari on MacBook)!?.. anyway, hopefully my bug-report with it's fix helps improving your product.

Thanks
Heider

@vincentle89 vincentle89 self-assigned this Feb 26, 2020
@m2-assistant
Copy link

m2-assistant bot commented Feb 26, 2020

Hi @vincent-le89. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!


@HeiderSati
Copy link
Author

Hi Vincent,

Thank you for picking this up.

I read your comments, all you need is already in the ticket (the problem, the code-part, the exact line in the code, and how to fix).

This should be really easy for you,

Again, the catch() function you have there is trying to display $template variable when it's not already defined, causing a different error (double-fault), you need to instance it (i.e. add -----> $template="") before the try() block so that it's catch() would work and return the real error,

@vincentle89
Copy link
Contributor

@HeiderSati I believe that it will be released on version 2.4. Thanks
Cheers.

@magento-engcom-team
Copy link
Contributor

Hi @HeiderSati. Thank you for your report.
The issue has been fixed in #27026 by @vincent-le89 in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Mar 12, 2020
@magento-engcom-team magento-engcom-team added this to Done (last 30 days) in Community Backlog Mar 24, 2020
@magento-engcom-team magento-engcom-team added the Reported on 2.3.4 Indicates original Magento version for the Issue report. label Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend Award: bug fix Component: Theme Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Reported on 2.3.4 Indicates original Magento version for the Issue report.
Projects
No open projects
Community Backlog
  
Done (last 30 days)
Development

Successfully merging a pull request may close this issue.

4 participants