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

Skip to content

Fixed exit code for exceptions with error code 0 #8183

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

Closed
wants to merge 2 commits into from

Conversation

Stelian
Copy link
Contributor

@Stelian Stelian commented Jun 3, 2013

Covers #8180

@@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}
$statusCode = $e->getCode();

$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write this as is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what it used to be before symfony/console@fcbb61c and I had no idea why it changed. Any idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was missing the integer cast. And I confused this exception code with the normal status code of a command return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated and re-ran tests. Everything seems to be in order now.

On Mon, Jun 3, 2013 at 4:22 PM, Tobias Schultze [email protected]:

In src/Symfony/Component/Console/Application.php:

@@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}
$statusCode = $e->getCode();

  •        $statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
    
  •        $statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 1;
    

It was missing the integer cast. And I confused this exception code with
the normal status code of a command return value.


Reply to this email directly or view it on GitHubhttps://github.com//pull/8183/files#r4500339
.

@Tobion
Copy link
Contributor

Tobion commented Jun 3, 2013

Thanks for fixing. This should be merged into 2.1 as I've done it wrong there.

@Stelian
Copy link
Contributor Author

Stelian commented Jun 3, 2013

Can someone redo the travis build please? It failed because of the stopwatch.

fabpot added a commit that referenced this pull request Jun 4, 2013
This PR was submitted for the 2.2 branch but it was merged into the 2.1 branch instead (closes #8183).

Discussion
----------

Fixed exit code for exceptions with error code 0

Covers #8180

Commits
-------

48e77f8 Fixed exit code for exceptions with error code 0
@fabpot
Copy link
Member

fabpot commented Jun 4, 2013

merged in 2.1

@fabpot fabpot closed this Jun 4, 2013
@@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}
$statusCode = $e->getCode();

$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
$statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this is still wrong. When $e->getCode(); returns 0.1, it will still return 0 as exit code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is not a use case we need to support. getCode should return an integer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to support that because getCode() can return mixed. This is why the is_numeric check is there at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tobion, you're right I will cover this use case within a couple of hours when I get home. @fabpot I think this has to be in the 2.2 also, as it is broken there as well, causing automated build tools like capistrano to not trigger alerts when commands fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #8202

everzet added a commit to everzet/symfony that referenced this pull request Jun 6, 2013
- Prevent negative and 0 exit code from being used on exception
- Prevent 255+ exit code from being used

Fixes symfony#8183, symfony#8202
egeloen pushed a commit to egeloen/symfony that referenced this pull request Nov 4, 2013
This PR was merged into the 2.1 branch.

Discussion
----------

[Console] fix status and exit code

Fix symfony#8183 (comment)
and
http://www.php.net/manual/en/function.exit.php
> Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

Commits
-------

6b9180a [Console] ensure exit code between 0-254
445b2e3 [Console] fix status code when Exception::getCode returns something like 0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants