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

Fatal error related to Logger #6175

Closed
piotrbak opened this issue Sep 18, 2023 · 4 comments · Fixed by #6212
Closed

Fatal error related to Logger #6175

piotrbak opened this issue Sep 18, 2023 · 4 comments · Fixed by #6212
Assignees
Labels
effort: [S] 1-2 days of estimated development time module: Logger needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. priority: medium Issues which are important, but no one will go out of business. type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@piotrbak
Copy link
Contributor

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version
  • Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug
When enabling debug mode, fatal error is triggered:

[18-Sep-2023 08:17:04 UTC] PHP Fatal error:  Uncaught Error: Class 'WP_Rocket\Dependencies\Monolog\Logger' not found in /home/zambvtks/public_html/wp-content/plugins/wp-rocket/inc/Logger/Logger.php:187

When tracing this part of advanced cache the following values are found:

[18-Sep-2023 09:05:26 UTC] $class = WP_Rocket\Dependencies\Monolog\Logger
[18-Sep-2023 09:05:26 UTC] $file = /var/www/html/wordpress/wp-content/plugins/wp-rocket/inc/Dependencies/Monolog/WP_Rocket/Dependencies/Monolog/Logger.php

The path is not correct.

To Reproduce
Steps to reproduce the behavior:

  1. Enable debug mode
  2. Check the error log

Expected behavior
No fatal errors happening

Additional context
https://wp-media.slack.com/archives/CUT7FLHF1/p1695028743176139

Acceptance Criteria (for WP Media team use only)

  1. Debug mode should work correctly only when enabled
  2. No regressions related to Conflict between Monolog 1.x and 2.x #5366 we should still be guarded against fatal errors that were fixed there
@piotrbak piotrbak added type: bug Indicates an unexpected problem or unintended behavior module: Logger priority: medium Issues which are important, but no one will go out of business. needs: grooming needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. labels Sep 18, 2023
@briceTouck
Copy link

Hi,

same issue,

Capture d’écran 2023-09-22 à 10 37 57 Capture d’écran 2023-09-22 à 10 38 43

Thank you

@CrochetFeve0251
Copy link
Contributor

CrochetFeve0251 commented Sep 25, 2023

Reproduce the problem

Just add the constant define('WP_ROCKET_DEBUG', true); and you should see it.

Identify the root cause

The root cause is due to the prefix added by Mozart which makes the autoload search in the wrong file.

Scope a solution

To solve that issue we will have to change the advanced-cache.php file:

} elseif ( strpos( $class, 'WP_Rocket\\Dependencies\\Monolog\\' ) === 0 ) {
                        $class = str_replace('WP_Rocket\\Dependencies\\Monolog\\', '', $class);

			$file = $rocket_path . 'inc/Dependencies/Monolog/' . str_replace( '\\', '/', $class ) . '.php';
			if ( ! file_exists( $file ) ) {
				$file = $rocket_path . 'vendor/monolog/monolog/src/' . str_replace( '\\', '/', $class ) . '.php';
			}
		} elseif ( strpos( $class, 'WP_Rocket\\Dependencies\\Psr\\Log\\' ) === 0 ) {
                      $file = $rocket_path . 'inc/Dependencies/Psr/Log/' . str_replace( '\\', '/', $class ) . '.php';

			$file = $rocket_path . 'inc/Dependencies/Psr/Log/' . str_replace( '\\', '/', $class ) . '.php';
			if ( ! file_exists( $file ) ) {
				$file = $rocket_path . 'vendor/psr/log/' . str_replace( '\\', '/', $class ) . '.php';
			}
		} else {

Then we will have to update advanced-cache.php on update from wpr inside PurgeActionsSubscriber:

public function on_update( $new_version, $old_version ) {
		if ( version_compare( $old_version, '3.12', '>=' ) ) {
			return;
		}
		rocket_generate_advanced_cache_file();
	}

Estimate the effort

Effort S

@CrochetFeve0251 CrochetFeve0251 added effort: [XS] < 1 day of estimated development time and removed needs: grooming labels Sep 25, 2023
@engahmeds3ed
Copy link
Contributor

@CrochetFeve0251 plz make sure that we regenerate advanced-cache.php file upon update.

Also do we need to do the same added str_replace to the psr/log package?

@CrochetFeve0251
Copy link
Contributor

@engahmeds3ed true I gonna add the logic to regenarate the advanced-cache.php.

Concerning the psr/log yes we do.

@CrochetFeve0251 CrochetFeve0251 added effort: [S] 1-2 days of estimated development time and removed effort: [XS] < 1 day of estimated development time labels Oct 2, 2023
@Miraeld Miraeld self-assigned this Oct 9, 2023
Miraeld added a commit that referenced this issue Oct 10, 2023
This commit contains the logic.
Miraeld added a commit that referenced this issue Oct 10, 2023
This commit contains the logic.
Miraeld added a commit that referenced this issue Oct 10, 2023
This commit contains the logic.
@piotrbak piotrbak added this to the 3.15.3 milestone Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [S] 1-2 days of estimated development time module: Logger needs: r&d Needs research and development (R&D) before a solution can be proposed and scoped. priority: medium Issues which are important, but no one will go out of business. type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants