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

[TASK] Streamline and fix exception handler code #189

Merged
merged 1 commit into from
Jun 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 17 additions & 25 deletions Classes/Error/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,16 @@ public function __construct()
/**
* Formats and echoes the exception for the command line
*
* @param \Exception $exception The exception object
* @param \Exception|\Throwable $exception The exception object
* @return void
*/
public function handleException($exception)
{
$pathPosition = strpos($exception->getFile(), 'ext/');
$filePathAndName = ($pathPosition !== false) ? substr($exception->getFile(), $pathPosition) : $exception->getFile();

$exceptionCodeNumber = ($exception->getCode() > 0) ? '#' . $exception->getCode() . ': ' : '';

echo PHP_EOL . 'Uncaught Exception in TYPO3 CMS ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
echo 'thrown in file ' . $filePathAndName . PHP_EOL;
echo 'in line ' . $exception->getLine() . PHP_EOL;
if ($exception instanceof \TYPO3\Flow\Exception) {
echo 'Reference code: ' . $exception->getReferenceCode() . PHP_EOL;
}

$this->outputSingleException($exception);
$indent = ' ';
while (($exception = $exception->getPrevious()) !== null) {
echo PHP_EOL . $indent . 'Nested exception:' . PHP_EOL;
$pathPosition = strpos($exception->getFile(), 'Packages/');
$filePathAndName = ($pathPosition !== false) ? substr($exception->getFile(), $pathPosition) : $exception->getFile();

$exceptionCodeNumber = ($exception->getCode() > 0) ? '#' . $exception->getCode() . ': ' : '';

echo PHP_EOL . $indent . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
echo $indent . 'thrown in file ' . $filePathAndName . PHP_EOL;
echo $indent . 'in line ' . $exception->getLine() . PHP_EOL;
if ($exception instanceof \TYPO3\Flow\Exception) {
echo 'Reference code: ' . $exception->getReferenceCode() . PHP_EOL;
}

$this->outputSingleException($exception, $indent);
$indent .= ' ';
}

Expand All @@ -87,4 +65,18 @@ public function handleException($exception)
echo PHP_EOL;
exit(1);
}

/**
* @param \Exception|\Throwable $exception
* @param string $indent
*/
protected function outputSingleException($exception, $indent = '')
{
$pathPosition = strpos($exception->getFile(), 'ext/');
$filePathAndName = ($pathPosition !== false) ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
$exceptionCodeNumber = ($exception->getCode() > 0) ? '#' . $exception->getCode() . ': ' : '';
echo PHP_EOL . $indent . 'Uncaught Exception in TYPO3 CMS: ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
echo $indent . 'thrown in file ' . $filePathAndName . PHP_EOL;
echo $indent . 'in line ' . $exception->getLine() . PHP_EOL;
}
}