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

(At least) Non-interactive commands should write errors to STDERR #2270

Open
InvisibleSmiley opened this issue Apr 2, 2024 · 4 comments · May be fixed by #2317
Open

(At least) Non-interactive commands should write errors to STDERR #2270

InvisibleSmiley opened this issue Apr 2, 2024 · 4 comments · May be fixed by #2317
Labels

Comments

@InvisibleSmiley
Copy link

Right now commands like migrate write errors to STDOUT. This is wrong. Errors, especially from commands that are commonly used non-interactively, need to be written to STDERR so that scripts executing Phinx can easily distinguish between information (STDOUT) and errors (STDERR), possibly redirecting either of them to different locations.

Here's how:
https://symfony.com/doc/current/console/style.html#writing-to-the-error-output

@dereuromark dereuromark added the bug label Apr 2, 2024
@derikb
Copy link

derikb commented Oct 15, 2024

+1 to this. We are using AWS CodeDeploy and have phinx migrations running via a bash script. Because the errors aren't going to stderr the script just happily continues on its way when phinx errors out without triggering any of our error handlers.

@dereuromark
Copy link
Member

Maybe someone wants to make a PR. I am sure it can be fast tracked.

@derikb
Copy link

derikb commented Oct 15, 2024

I would if I had the slightest clue how any of this works. We don't use Symfony otherwise, so it's a bit of a learning curve to figure out where to even make this happen...

would it be in the various commands at this point (using Migrate as an example):

$output->writeln('<error>' . $e->__toString() . '</error>');
where instead of writeln one would use the SymfonyStyle error style per the link in the issue description?

@InvisibleSmiley
Copy link
Author

InvisibleSmiley commented Oct 15, 2024

I'll try to work on this within the next two days. Originally I thought it was so easy and straightforward that I only created the issue with pointers at the solution path, but then lost track of it.

Basically it's merely adding this at the beginning of all command execute methods and then replacing $ouput by $errorStyle whereever output shall be written to STDERR (if available):

$io = new SymfonyStyle($input, $output);
$errorStyle = $io->getErrorStyle();

(of course SymfonyStyle needs to be imported).

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

Successfully merging a pull request may close this issue.

3 participants