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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

if ($this->autoExit) {
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,21 @@ public function testRunReturnsIntegerExitCode()
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
}

public function testRunReturnsExitCodeOneForExceptionCodeZero()
{
$exception = new \Exception('', 0);

$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
$application->setAutoExit(false);
$application->expects($this->once())
->method('doRun')
->will($this->throwException($exception));

$exitCode = $application->run(new ArrayInput(array()), new NullOutput());

$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
}

/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData
Expand Down