Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[2.1] Added missing error return codes in commands #5586

Closed
wants to merge 3 commits into from

3 participants

@hason

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
See: #5585

@fabpot
Owner

Exit code values are standardized and some values have some well-defined meaning. Have a look here for more info: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Process/Process.php#L67

@stof stof commented on the diff
.../FrameworkBundle/Command/TranslationUpdateCommand.php
@@ -92,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>Wrong output format</error>');
$output->writeln('Supported formats are '.implode(', ', $supportedFormats).'.');
- return;
+ return self::RETURN_CODE_UNSUPPORTED_FORMAT;
@stof Collaborator
stof added a note

@hason please change it to return 1 in both cases as returning 2 is wrong according to its meaning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot merged branch hason/return_code (PR #5586)
This PR was squashed before being merged into the 2.1 branch (closes #5586).

Commits
-------

6b66bc3 [2.1] Added missing error return codes in commands

Discussion
----------

[2.1] Added missing error return codes in commands

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
See: #5585

---------------------------------------------------------------------------

by fabpot at 2012-09-24T12:10:47Z

Exit code values are standardized and some values have some well-defined meaning. Have a look here for more info: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Process/Process.php#L67
98070d5
@fabpot fabpot closed this pull request from a commit
@fabpot fabpot merged branch hason/return_code (PR #5586)
This PR was squashed before being merged into the 2.1 branch (closes #5586).

Commits
-------

6b66bc3 [2.1] Added missing error return codes in commands

Discussion
----------

[2.1] Added missing error return codes in commands

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
See: #5585

---------------------------------------------------------------------------

by fabpot at 2012-09-24T12:10:47Z

Exit code values are standardized and some values have some well-defined meaning. Have a look here for more info: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Process/Process.php#L67
98070d5
@fabpot fabpot closed this in 98070d5
@mmucklo mmucklo referenced this pull request from a commit
@fabpot fabpot merged branch hason/return_code (PR #5586)
This PR was squashed before being merged into the 2.1 branch (closes #5586).

Commits
-------

6b66bc3 [2.1] Added missing error return codes in commands

Discussion
----------

[2.1] Added missing error return codes in commands

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
See: #5585

---------------------------------------------------------------------------

by fabpot at 2012-09-24T12:10:47Z

Exit code values are standardized and some values have some well-defined meaning. Have a look here for more info: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Process/Process.php#L67
5640f2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php
@@ -84,6 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$matches) {
$output->writeln('<fg=red>None of the routes matches</>');
+
+ return 1;
}
}
}
View
8 src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
@@ -26,6 +26,10 @@
*/
class TranslationUpdateCommand extends ContainerAwareCommand
{
+ const RETURN_CODE_MISSING_OPTIONS = 1;
+
+ const RETURN_CODE_UNSUPPORTED_FORMAT = 2;
+
/**
* Compiled catalogue of messages.
* @var MessageCatalogue
@@ -82,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
- return;
+ return self::RETURN_CODE_MISSING_OPTIONS;
}
// check format
@@ -92,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>Wrong output format</error>');
$output->writeln('Supported formats are '.implode(', ', $supportedFormats).'.');
- return;
+ return self::RETURN_CODE_UNSUPPORTED_FORMAT;
@stof Collaborator
stof added a note

@hason please change it to return 1 in both cases as returning 2 is wrong according to its meaning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
// get bundle directory
View
2  src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php
@@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} catch (SchemaException $e) {
$output->writeln("Aborting: " . $e->getMessage());
- return;
+ return 1;
}
foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
View
44 src/Symfony/Bundle/TwigBundle/Command/LintCommand.php
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$template .= fread(STDIN, 1024);
}
- return $twig->parse($twig->tokenize($template));
+ return $this->validateTemplate($twig, $output, $template);
}
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
@@ -87,26 +87,39 @@ protected function execute(InputInterface $input, OutputInterface $output)
$files = Finder::create()->files()->in($dir)->name('*.twig');
}
- $error = false;
+ $errors = 0;
foreach ($files as $file) {
- try {
- $twig->parse($twig->tokenize(file_get_contents($file), (string) $file));
- $output->writeln(sprintf("<info>OK</info> in %s", $file));
- } catch (\Twig_Error $e) {
- $this->renderException($output, $file, $e);
- $error = true;
- }
+ $errors += $this->validateTemplate($twig, $output, file_get_contents($file), $file);
+ }
+
+ return $errors > 0 ? 1 : 0;
+ }
+
+ protected function validateTemplate(\Twig_Environment $twig, OutputInterface $output, $template, $file = null)
+ {
+ try {
+ $twig->parse($twig->tokenize($template, $file ? (string) $file : null));
+ $output->writeln('<info>OK</info>'.($file ? sprintf(' in %s', $file) : ''));
+ } catch (\Twig_Error $e) {
+ $this->renderException($output, $template, $e, $file);
+
+ return 1;
}
- return $error ? 1 : 0;
+ return 0;
}
- protected function renderException(OutputInterface $output, $file, \Twig_Error $exception)
+ protected function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null)
{
$line = $exception->getTemplateLine();
- $lines = $this->getContext($file, $line);
+ $lines = $this->getContext($template, $line);
+
+ if ($file) {
+ $output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
+ } else {
+ $output->writeln(sprintf("<error>KO</error> (line %s)", $line));
+ }
- $output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
foreach ($lines as $no => $code) {
$output->writeln(sprintf(
"%s %-6s %s",
@@ -120,10 +133,9 @@ protected function renderException(OutputInterface $output, $file, \Twig_Error $
}
}
- protected function getContext($file, $line, $context = 3)
+ protected function getContext($template, $line, $context = 3)
{
- $fileContent = file_get_contents($file);
- $lines = explode("\n", $fileContent);
+ $lines = explode("\n", $template);
$position = max(0, $line - $context);
$max = min(count($lines), $line - 1 + $context);
Something went wrong with that request. Please try again.