Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76e7944

Browse files
[Debug][HttpKernel] remove frames added by DebugClassLoader in stack traces
1 parent6eb5f93 commit76e7944

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

‎src/Symfony/Component/Debug/ErrorHandler.php‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ public function handleError($type, $message, $file, $line)
417417
self::$toStringException =null;
418418
}elseif (!$throw && !($type &$level)) {
419419
if (!isset(self::$silencedErrorCache[$id =$file.':'.$line])) {
420-
$lightTrace =$this->tracedErrors &$type ?$this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,3),$type,$file,$line,false) :array();
421-
$errorAsException =newSilencedErrorContext($type,$file,$line,$lightTrace);
420+
$lightTrace =$this->tracedErrors &$type ?$this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,5),$type,$file,$line,false) :array();
421+
$errorAsException =newSilencedErrorContext($type,$file,$line,isset($lightTrace[1]) ?array($lightTrace[0]) :$lightTrace);
422422
}elseif (isset(self::$silencedErrorCache[$id][$message])) {
423423
$lightTrace =null;
424424
$errorAsException =self::$silencedErrorCache[$id][$message];
@@ -441,7 +441,6 @@ public function handleError($type, $message, $file, $line)
441441
}else {
442442
$errorAsException =new \ErrorException($logMessage,0,$type,$file,$line);
443443

444-
// Clean the trace by removing function arguments and the first frames added by the error handler itself.
445444
if ($throw ||$this->tracedErrors &$type) {
446445
$backtrace =$errorAsException->getTrace();
447446
$lightTrace =$this->cleanTrace($backtrace,$type,$file,$line,$throw);
@@ -669,6 +668,9 @@ protected function getFatalErrorHandlers()
669668
);
670669
}
671670

671+
/**
672+
* Cleans the trace by removing function arguments and the frames added by the error handler and DebugClassLoader.
673+
*/
672674
privatefunctioncleanTrace($backtrace,$type,$file,$line,$throw)
673675
{
674676
$lightTrace =$backtrace;
@@ -679,6 +681,13 @@ private function cleanTrace($backtrace, $type, $file, $line, $throw)
679681
break;
680682
}
681683
}
684+
if (class_exists(DebugClassLoader::class,false)) {
685+
for ($i =\count($lightTrace) -2;0 <$i; --$i) {
686+
if (DebugClassLoader::class === ($lightTrace[$i]['class'] ??null)) {
687+
array_splice($lightTrace, --$i,2);
688+
}
689+
}
690+
}
682691
if (!($throw ||$this->scopedErrors &$type)) {
683692
for ($i =0;isset($lightTrace[$i]); ++$i) {
684693
unset($lightTrace[$i]['args'],$lightTrace[$i]['object']);

‎src/Symfony/Component/HttpKernel/Kernel.php‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
useSymfony\Component\Config\ConfigCache;
1717
useSymfony\Component\Config\Loader\DelegatingLoader;
1818
useSymfony\Component\Config\Loader\LoaderResolver;
19+
useSymfony\Component\Debug\DebugClassLoader;
1920
useSymfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
2021
useSymfony\Component\DependencyInjection\Compiler\PassConfig;
2122
useSymfony\Component\DependencyInjection\ContainerBuilder;
@@ -504,21 +505,28 @@ protected function initializeContainer()
504505
return;
505506
}
506507

507-
$backtrace =debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,3);
508+
$backtrace =debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,5);
508509
// Clean the trace by removing first frames added by the error handler itself.
509510
for ($i =0;isset($backtrace[$i]); ++$i) {
510511
if (isset($backtrace[$i]['file'],$backtrace[$i]['line']) &&$backtrace[$i]['line'] ===$line &&$backtrace[$i]['file'] ===$file) {
511512
$backtrace =\array_slice($backtrace,1 +$i);
512513
break;
513514
}
514515
}
516+
// Remove frames added by DebugClassLoader.
517+
for ($i =\count($backtrace) -2;0 <$i; --$i) {
518+
if (DebugClassLoader::class === ($backtrace[$i]['class'] ??null)) {
519+
$backtrace =array($backtrace[$i +1]);
520+
break;
521+
}
522+
}
515523

516524
$collectedLogs[$message] =array(
517525
'type' =>$type,
518526
'message' =>$message,
519527
'file' =>$file,
520528
'line' =>$line,
521-
'trace' =>$backtrace,
529+
'trace' =>array($backtrace[0]),
522530
'count' =>1,
523531
);
524532
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp