Skip to content

Commit 5c9c771

Browse files
committed
MAGETWO-96507: Fixed incorrect stacktrace displaying
1 parent 5b3adc5 commit 5c9c771

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

.htaccess

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
############################################
3131
## default index file
32+
## Specifies option, to use methods arguments in backtrace or not
33+
SetEnv MAGE_DEBUG_SHOW_ARGS 1
3234

3335
DirectoryIndex index.php
3436

lib/internal/Magento/Framework/App/Http.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Framework\App;
77

88
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Debug;
910
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
1011
use Magento\Framework\App\Request\Http as RequestHttp;
1112
use Magento\Framework\App\Response\Http as ResponseHttp;
@@ -79,7 +80,7 @@ class Http implements \Magento\Framework\AppInterface
7980
* @param ResponseHttp $response
8081
* @param ConfigLoaderInterface $configLoader
8182
* @param State $state
82-
* @param Filesystem $filesystem,
83+
* @param Filesystem $filesystem
8384
* @param \Magento\Framework\Registry $registry
8485
*/
8586
public function __construct(
@@ -149,7 +150,7 @@ public function launch()
149150
}
150151

151152
/**
152-
* {@inheritdoc}
153+
* @inheritdoc
153154
*/
154155
public function catchException(Bootstrap $bootstrap, \Exception $exception)
155156
{
@@ -198,6 +199,7 @@ private function buildContentFromException(\Exception $exception)
198199
{
199200
/** @var \Exception[] $exceptions */
200201
$exceptions = [];
202+
201203
do {
202204
$exceptions[] = $exception;
203205
} while ($exception = $exception->getPrevious());
@@ -214,7 +216,12 @@ private function buildContentFromException(\Exception $exception)
214216
$index,
215217
get_class($exception),
216218
$exception->getMessage(),
217-
$exception->getTraceAsString()
219+
Debug::trace(
220+
$exception->getTrace(),
221+
true,
222+
true,
223+
(bool)getenv('MAGE_DEBUG_SHOW_ARGS')
224+
)
218225
);
219226
}
220227

@@ -312,7 +319,15 @@ private function handleInitException(\Exception $exception)
312319
*/
313320
private function handleGenericReport(Bootstrap $bootstrap, \Exception $exception)
314321
{
315-
$reportData = [$exception->getMessage(), $exception->getTraceAsString()];
322+
$reportData = [
323+
$exception->getMessage(),
324+
Debug::trace(
325+
$exception->getTrace(),
326+
true,
327+
true,
328+
(bool)getenv('MAGE_DEBUG_SHOW_ARGS')
329+
)
330+
];
316331
$params = $bootstrap->getParams();
317332
if (isset($params['REQUEST_URI'])) {
318333
$reportData['url'] = $params['REQUEST_URI'];

lib/internal/Magento/Framework/App/StaticResource.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Filesystem;
1111
use Magento\Framework\Config\ConfigOptionsListConstants;
1212
use Psr\Log\LoggerInterface;
13+
use Magento\Framework\Debug;
1314

1415
/**
1516
* Entry point for retrieving static resources like JS, CSS, images by requested public path
@@ -54,12 +55,12 @@ class StaticResource implements \Magento\Framework\AppInterface
5455
private $objectManager;
5556

5657
/**
57-
* @var \Magento\Framework\ObjectManager\ConfigLoaderInterface
58+
* @var ConfigLoaderInterface
5859
*/
5960
private $configLoader;
6061

6162
/**
62-
* @var \Magento\Framework\Filesystem
63+
* @var Filesystem
6364
*/
6465
private $filesystem;
6566

@@ -69,7 +70,7 @@ class StaticResource implements \Magento\Framework\AppInterface
6970
private $deploymentConfig;
7071

7172
/**
72-
* @var \Psr\Log\LoggerInterface
73+
* @var LoggerInterface
7374
*/
7475
private $logger;
7576

@@ -138,15 +139,23 @@ public function launch()
138139
}
139140

140141
/**
141-
* {@inheritdoc}
142+
* @inheritdoc
142143
*/
143144
public function catchException(Bootstrap $bootstrap, \Exception $exception)
144145
{
145146
$this->getLogger()->critical($exception->getMessage());
146147
if ($bootstrap->isDeveloperMode()) {
147148
$this->response->setHttpResponseCode(404);
148149
$this->response->setHeader('Content-Type', 'text/plain');
149-
$this->response->setBody($exception->getMessage() . "\n" . $exception->getTraceAsString());
150+
$this->response->setBody(
151+
$exception->getMessage() . "\n" .
152+
Debug::trace(
153+
$exception->getTrace(),
154+
true,
155+
true,
156+
(bool)getenv('MAGE_DEBUG_SHOW_ARGS')
157+
)
158+
);
150159
$this->response->sendResponse();
151160
} else {
152161
require $this->getFilesystem()->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/404.php');

lib/internal/Magento/Framework/Message/Manager.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\Event;
99
use Psr\Log\LoggerInterface;
1010
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Debug;
1112

1213
/**
1314
* Message manager model
@@ -67,7 +68,7 @@ class Manager implements ManagerInterface
6768
* @param Event\ManagerInterface $eventManager
6869
* @param LoggerInterface $logger
6970
* @param string $defaultGroup
70-
* @param ExceptionMessageFactoryInterface|null exceptionMessageFactory
71+
* @param ExceptionMessageFactoryInterface|null $exceptionMessageFactory
7172
*/
7273
public function __construct(
7374
Session $session,
@@ -89,7 +90,7 @@ public function __construct(
8990
}
9091

9192
/**
92-
* {@inheritdoc}
93+
* @inheritdoc
9394
*/
9495
public function getDefaultGroup()
9596
{
@@ -110,8 +111,8 @@ protected function prepareGroup($group)
110111
/**
111112
* @inheritdoc
112113
*
113-
* @param string|null $group
114114
* @param bool $clear
115+
* @param string|null $group
115116
* @return Collection
116117
*/
117118
public function getMessages($clear = false, $group = null)
@@ -248,7 +249,12 @@ public function addException(\Exception $exception, $alternativeText = null, $gr
248249
'Exception message: %s%sTrace: %s',
249250
$exception->getMessage(),
250251
"\n",
251-
$exception->getTraceAsString()
252+
Debug::trace(
253+
$exception->getTrace(),
254+
true,
255+
true,
256+
(bool)getenv('MAGE_DEBUG_SHOW_ARGS')
257+
)
252258
);
253259

254260
$this->logger->critical($message);
@@ -286,7 +292,12 @@ public function addExceptionMessage(\Exception $exception, $alternativeText = nu
286292
'Exception message: %s%sTrace: %s',
287293
$exception->getMessage(),
288294
"\n",
289-
$exception->getTraceAsString()
295+
Debug::trace(
296+
$exception->getTrace(),
297+
true,
298+
true,
299+
(bool)getenv('MAGE_DEBUG_SHOW_ARGS')
300+
)
290301
);
291302

292303
$this->logger->critical($message);

0 commit comments

Comments
 (0)