Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bdada47
[Translation] Added CsvFileLoader to support csv translation resources.
umpirsky Jan 8, 2011
e85546e
[DependencyInjection] made some improvments to the container compiler
schmittjoh Jan 8, 2011
d1a2a65
[DependencyInjection] performance improvement, better analysis tools
schmittjoh Jan 9, 2011
f1e41a9
[DependencyInjection] made some improvments to the container compiler
schmittjoh Jan 9, 2011
99a5097
[HttpFoundation] Correcting the PHPDoc for the public $headers proper…
weaverryan Jan 9, 2011
09a876b
[HttpFoundation] Adding a few internal notes to clarify the process o…
weaverryan Jan 9, 2011
361a0dc
[Translation] Adding PHPDoc to the MessageSelector::choose() method.
weaverryan Jan 9, 2011
98c787a
[CompatAssetsBundle] Add missing namespace
ornicar Jan 10, 2011
dedf29f
[HttpKernel] No longer reformat {} "a la python"
igorw Jan 9, 2011
3734c0e
updated bootstrap file
fabpot Jan 10, 2011
d6b57bc
[HttpFoundation] fixed error casting broken in DomCrawler\Form::getPh…
avalanche123 Jan 10, 2011
7cab551
[FrameworkBundle] removed public=false from security.encoder_factory
ruudk Jan 11, 2011
c85b587
made security.acl.dbal.connection public for use in acl:init
Jan 10, 2011
18a34c5
[DoctrineBundle] Changed visibility of doctrine db connections to public
Jan 10, 2011
f41654f
[Console] added rendering previous exceptions
hason Jan 11, 2011
08c3a2b
method buildContainer divided into logical parts
hason Jan 10, 2011
9a2e053
[Event] Collected data is about listener (not event) calls
vicb Jan 9, 2011
47b87e9
[TwigBundle] made global more powerful
fabpot Jan 11, 2011
4beac30
[Form, FrameworkBundle] added csrf tokens reset on Kernel::shutdown()…
avalanche123 Jan 11, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Console] added rendering previous exceptions
  • Loading branch information
hason authored and fabpot committed Jan 11, 2011
commit f41654fd6064c2f550fa82af3b40878f09df46e7
82 changes: 42 additions & 40 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,55 +657,57 @@ public function renderException($e, $output)
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
};

$title = sprintf(' [%s] ', get_class($e));
$len = $strlen($title);
$lines = array();
foreach (explode("\n", $e->getMessage()) as $line) {
$lines[] = sprintf(' %s ', $line);
$len = max($strlen($line) + 4, $len);
}

$messages = array(str_repeat(' ', $len), $title.str_repeat(' ', $len - $strlen($title)));
do {
$title = sprintf(' [%s] ', get_class($e));
$len = $strlen($title);
$lines = array();
foreach (explode("\n", $e->getMessage()) as $line) {
$lines[] = sprintf(' %s ', $line);
$len = max($strlen($line) + 4, $len);
}

foreach ($lines as $line) {
$messages[] = $line.str_repeat(' ', $len - $strlen($line));
}
$messages = array(str_repeat(' ', $len), $title.str_repeat(' ', $len - $strlen($title)));

$messages[] = str_repeat(' ', $len);
foreach ($lines as $line) {
$messages[] = $line.str_repeat(' ', $len - $strlen($line));
}

$output->writeln("\n");
foreach ($messages as $message) {
$output->writeln('<error>'.$message.'</error>');
}
$output->writeln("\n");
$messages[] = str_repeat(' ', $len);

if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
$output->writeln("\n");
}

if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
$output->writeln('</comment>Exception trace:</comment>');

// exception related properties
$trace = $e->getTrace();
array_unshift($trace, array(
'function' => '',
'file' => $e->getFile() != null ? $e->getFile() : 'n/a',
'line' => $e->getLine() != null ? $e->getLine() : 'n/a',
'args' => array(),
));
foreach ($messages as $message) {
$output->writeln('<error>'.$message.'</error>');
}
$output->writeln("\n");

for ($i = 0, $count = count($trace); $i < $count; $i++) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$function = $trace[$i]['function'];
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
if (Output::VERBOSITY_VERBOSE === $output->getVerbosity()) {
$output->writeln('</comment>Exception trace:</comment>');

// exception related properties
$trace = $e->getTrace();
array_unshift($trace, array(
'function' => '',
'file' => $e->getFile() != null ? $e->getFile() : 'n/a',
'line' => $e->getLine() != null ? $e->getLine() : 'n/a',
'args' => array(),
));

for ($i = 0, $count = count($trace); $i < $count; $i++) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$function = $trace[$i]['function'];
$file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';

$output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
}

$output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
$output->writeln("\n");
}
} while ($e = $e->getPrevious());

if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
$output->writeln("\n");
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Symfony/Tests/Component/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static public function setUpBeforeClass()
require_once self::$fixturesPath.'/FooCommand.php';
require_once self::$fixturesPath.'/Foo1Command.php';
require_once self::$fixturesPath.'/Foo2Command.php';
require_once self::$fixturesPath.'/Foo3Command.php';
}

protected function normalize($text)
Expand Down Expand Up @@ -245,6 +246,12 @@ public function testRenderException()

$tester->run(array('command' => 'list', '--foo' => true));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $this->normalize($tester->getDisplay()), '->renderException() renders the command synopsis when an exception occurs in the context of a command');

$application->add(new \Foo3Command);
$tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo3:bar'));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $this->normalize($tester->getDisplay()), '->renderException() renders a pretty exceptions with previous exceptions');

}

public function testRun()
Expand Down
25 changes: 25 additions & 0 deletions tests/Symfony/Tests/Component/Console/Fixtures/Foo3Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Foo3Command extends Command
{
protected function configure()
{
$this
->setName('foo3:bar')
->setDescription('The foo3:bar command')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
try {
throw new \Exception("First exception");
} catch (\Exception $e) {
throw new \Exception("Second exception", 0, $e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@



[Exception]
Second exception






[Exception]
First exception



foo3:bar [-h|--help] [-q|--quiet] [-v|--verbose] [-V|--version] [-a|--ansi] [-n|--no-interaction] command