8000 Php error in console command returns wrong exit code · Issue #54351 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

Php error in console command returns wrong exit code #54351

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
b1rdex opened this issue Mar 20, 2024 · 5 comments
Closed

Php error in console command returns wrong exit code #54351

b1rdex opened this issue Mar 20, 2024 · 5 comments

Comments

@b1rdex
Copy link
Contributor
b1rdex commented Mar 20, 2024

Symfony version(s) affected

v7.0.4

Description

Error in PHP code throws an Error. This error is rendered with error style. But the command exit code is 0.

How to reproduce

#[AsCommand(
    name: 'app:error',
)]
class ErrorCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $foo = null;
		// next line throws an Error
        $foo->bar();

        return Command::INVALID;
	}
}

Run symfony console app:error ; echo 'exit code: '$?

See the 0 exit code:

❯ symfony console app:error ; echo $?

In ErrorCommand.php line 27:
                                           
  Call to a member function bar() on null  
                                           

app:test-import

exit code: 0

Possible Solution

Here was a wrong idea, I removed it to simplify the issue. See the comments.

Additional Context

No response

@b1rdex

This comment was marked as outdated.

@b1rdex
Copy link
Contributor Author
b1rdex commented Mar 20, 2024

Ok, got it. If I set \Symfony\Component\Console\Application::$catchErrors = true then I got a correct exit code = 1.

Is this by design? Why default runtime (vendor/autoload_runtime.php + SymfonyRuntime) hides the command execution error with exit code 0?

@xabbuh xabbuh added the Console label Mar 20, 2024
@xabbuh
Copy link
Member
xabbuh commented Mar 20, 2024

Same as #53946?

@b1rdex
Copy link
Contributor Author
b1rdex commented Mar 20, 2024

Yes it is. Thanks. I fixed it the same way as in #53946 (comment).

@b1rdex b1rdex closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@stof
Copy link
Member
stof commented Mar 20, 2024

Note that the root cause of the issue should be fixed in the next PHP 8.3.x release as a fix has been merged in php-src.

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
0