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

Console ErrorHandler does not set correct exit code / return value #15202

Closed
SamMousa opened this issue Nov 22, 2017 · 3 comments
Closed

Console ErrorHandler does not set correct exit code / return value #15202

SamMousa opened this issue Nov 22, 2017 · 3 comments

Comments

@SamMousa
Copy link
Contributor

What steps will reproduce the problem?

Create a console command that throws an exception:

public function actionFail() {
    throw new \Exception("An exception is not ideal");
}

What is the expected result?

A non-zero return value.

What do you get instead?

A zero return value (https://github.com/yiisoft/yii2/blob/master/framework/base/ErrorHandler.php#L112)

...
            if (!YII_ENV_TEST) {
                \Yii::getLogger()->flush(true);
                if (defined('HHVM_VERSION')) {
                    flush();
                }
                exit(1);
            }

To me it would make more sense to always return exit code 1 in case we are handling an exception, no matter the environment.

@klimov-paul
Copy link
Member

klimov-paul commented Nov 22, 2017

Disagreed.
The code block you refer prevents application termination in case of exception in test mode.
Console application is often used during unit test running. Enforcing exit on error will cause it to terminate PHPUnit script.

@samdark
Copy link
Member

samdark commented Nov 24, 2017

Agree with @klimov-paul. The reason for handing it differently is running tests for commands.

@egorrishe
Copy link
Contributor

Hi!
I've read carefully this and all similar issues. And I understand why behavior works so.
I don't ask to change it permanently. I suggest to provide possibility to manage this behavior.
Because it is problem, if you are running some console command while Continuous Integration.

Real Example:

  • this Travis build marked as passed. But really there was a bug - fixtures were not applied because one of them crashed:
  • that's why CI can't know, that Error occurred - problem

Additionally
I've tried to workaround this problem with ExitException: throw \yii\base\ExitException(1, 'error', 1);. But exit code still 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants