Skip to content

Commit

Permalink
10.4.6: #342
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Dec 9, 2023
1 parent 274812f commit b65a2c9
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
30 changes: 30 additions & 0 deletions Framework/Log/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ function handle(array $d):bool {
}
df_sentry(null, $v, $extra);
}
/**
* 2023-12-09
* 1) Some errors are logged twice: by @see \Df\Framework\Log\Dispatcher::handle()
* and @see \Df\Framework\Plugin\AppInterface::beforeCatchException():
* https://github.com/mage2pro/core/issues/342
* 2) @see \Magento\Framework\App\Bootstrap::run():
* $this->objectManager->get(LoggerInterface::class)->error($e->getMessage());
* if (!$application->catchException($this, $e)) {
* throw $e;
* }
* https://github.com/magento/magento2/blob/2.4.7-beta2/lib/internal/Magento/Framework/App/Bootstrap.php#L269-L272
* 3) The call stack:
* 3.1) @see \Magento\Framework\App\Bootstrap::run()
* $this->objectManager->get(LoggerInterface::class)->error($e->getMessage());
* https://github.com/magento/magento2/blob/2.4.5/lib/internal/Magento/Framework/App/Bootstrap.php#L269
* 3.2) @see \Magento\Framework\Logger\LoggerProxy::error()
* $this->getLogger()->error($message, $context);
* https://github.com/magento/magento2/blob/2.4.5/lib/internal/Magento/Framework/Logger/LoggerProxy.php#L126
* 3.3) @see \Monolog\Logger::error()
* $this->addRecord(static::ERROR, (string) $message, $context);
* https://github.com/Seldaek/monolog/blob/2.9.2/src/Monolog/Logger.php#L650
* 3.4) @see \Monolog\Logger::addRecord()
* if (true === $handler->handle($record)) {
* https://github.com/Seldaek/monolog/blob/2.9.2/src/Monolog/Logger.php#L399
* 4) Magento ≥ 2.4.6 passes the exception to loggers:
* $context = $this->addExceptionToContext($message, $context);
* https://github.com/magento/magento2/blob/2.4.6/lib/internal/Magento/Framework/Logger/LoggerProxy.php#L129
* We can not use it because we need to support outdated Magento versions.
*/
Latest::register($rc);
}
$r = true; # 2020-09-24 The pevious code was: `$r = parent::handle($d);`
}
Expand Down
44 changes: 44 additions & 0 deletions Framework/Log/Latest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Df\Framework\Log;
use Monolog\Logger as L;
use \Exception as E;
/**
* 2023-12-09
* 1) Some errors are logged twice: by @see \Df\Framework\Log\Dispatcher::handle()
* and @see \Df\Framework\Plugin\AppInterface::beforeCatchException():
* https://github.com/mage2pro/core/issues/342
* 2) @see \Magento\Framework\App\Bootstrap::run():
* $this->objectManager->get(LoggerInterface::class)->error($e->getMessage());
* if (!$application->catchException($this, $e)) {
* throw $e;
* }
* https://github.com/magento/magento2/blob/2.4.7-beta2/lib/internal/Magento/Framework/App/Bootstrap.php#L269-L272
*/
final class Latest {
/**
* 2023-12-09
* @used-by \Df\Framework\Plugin\AppInterface::beforeCatchException()
*/
static function registered(E $e):bool {
$v = self::$v;
self::$v = null;
return $v === $e->getMessage();
}

/**
* 2023-12-09
* @used-by \Df\Framework\Log\Dispatcher::handle()
*/
static function register(Record $r):void {
if (L::ERROR === $r->level()) {
self::$v = $r->msg();
}
}

/**
* 2023-12-09
* @used-by self::register()
* @var string|null
*/
private static $v;
}
2 changes: 2 additions & 0 deletions Framework/Log/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function extra():array {return $this->d('extra');}
* 2023-08-01
* @used-by \Df\Framework\Log\Dispatcher::handle()
* @used-by \Df\Framework\Log\Handler\BrokenReference::_p()
* @used-by \Df\Framework\Log\Latest::register()
*/
function level():int {return $this->d('level');}

Expand All @@ -50,6 +51,7 @@ function level():int {return $this->d('level');}
* @used-by \Df\Framework\Log\Handler\Cookie::_p()
* @used-by \Df\Framework\Log\Handler\JsMap::_p()
* @used-by \Df\Framework\Log\Handler\PayPal::_p()
* @used-by \Df\Framework\Log\Latest::register()
* @param string|string[]|null $s [optional]
* @return string|bool
*/
Expand Down
20 changes: 18 additions & 2 deletions Framework/Plugin/AppInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Df\Framework\Plugin;
use Df\Framework\Log\Handler\JsMap;
use Df\Framework\Log\Latest;
use Magento\Framework\AppInterface as Sb;
use Magento\Framework\App\Bootstrap as B;
use \Exception as E;
Expand Down Expand Up @@ -54,8 +55,23 @@ final class AppInterface {
* https://github.com/magento/magento2/blob/2.4.3/lib/internal/Magento/Framework/App/StaticResource.php#L194-L214
*/
function beforeCatchException(Sb $sb, B $b, E $e):void {
# 2023-08-25 "Prevent logging of «Requested path <…>.js.map is wrong»": https://github.com/mage2pro/core/issues/323
if (!JsMap::is($e->getMessage())) {
/**
* 2023-08-25 "Prevent logging of «Requested path <…>.js.map is wrong»": https://github.com/mage2pro/core/issues/323
* 2023-12-09
* 1) Some errors are logged twice: by @see \Df\Framework\Log\Dispatcher::handle()
* and @see \Df\Framework\Plugin\AppInterface::beforeCatchException(): https://github.com/mage2pro/core/issues/342
* 2) @see \Magento\Framework\App\Bootstrap::run():
* $this->objectManager->get(LoggerInterface::class)->error($e->getMessage());
* if (!$application->catchException($this, $e)) {
* throw $e;
* }
* https://github.com/magento/magento2/blob/2.4.7-beta2/lib/internal/Magento/Framework/App/Bootstrap.php#L269-L272
* 3) Magento ≥ 2.4.6 passes the exception to loggers:
* $context = $this->addExceptionToContext($message, $context);
* https://github.com/magento/magento2/blob/2.4.6/lib/internal/Magento/Framework/Logger/LoggerProxy.php#L129
* We can not use it because we need to support outdated Magento versions.
*/
if (!JsMap::is($e->getMessage()) && !Latest::registered($e)) {
df_log($e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/core"
,"version": "10.4.5"
,"version": "10.4.6"
,"description": "Mage2.PRO core package."
,"type": "magento2-module"
,"homepage": "https://mage2.pro"
Expand Down

0 comments on commit b65a2c9

Please sign in to comment.