Skip to content

[FrameworkBundle] Make use of stderr for non reliable output #20632

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

Merged
merged 3 commits into from
Feb 19, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Nov 25, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Built-in commands should make use of the proper outputs.
As a feature on master, considering that people may actually rely on stdout and the fact commands have been changed a lot since 2.7, I think it's not worth doing this change on lower branches.

Please see also #20586 which adds a SymfonyStyle::getErrorStyle() shortcut for easily switching to stderr.

@ogizanagi
Copy link
Contributor

Isn't there a lot more than those 4 commands? What about LintCommand for instance? :)

(I guess keeping this in #20586 would be less painful to update as you target master too for this bug fix 😅)

@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch from b7af8c5 to b2920e7 Compare November 25, 2016 18:28
@chalasr
Copy link
Member Author

chalasr commented Nov 25, 2016

@ogizanagi I made the changes only where it makes sense in my opinion, which exclude commands where the output give no relevant information at all.

I just applied it on the TwigLintCommand which makes use of SymfonyStyle::error, because the output is intended to be redirected, but at the moment I don't see more commands to update.

I guess keeping this in #20586 would be less painful to update

Not that much, each one can be merged independently and, since the subject of #20586 was "Add getErrorIo AND use stderr in existing commands", I do think it should be done in two PRs :)

@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch from b2920e7 to 2207831 Compare November 25, 2016 18:41
@chalasr
Copy link
Member Author

chalasr commented Nov 25, 2016

Note that when exceptions are thrown (which is the case in lot of commands including lint ones), the output goes to stderr naturally.

@ogizanagi
Copy link
Contributor

@chalasr : I may have found some other places where it'll be relevant. See #20674

@chalasr
Copy link
Member Author

chalasr commented Nov 28, 2016

Oh, I could have did it here if you just said me.. but ok then

@ogizanagi
Copy link
Contributor

ogizanagi commented Nov 28, 2016

I had to check relevant places myself so it was simpler to submit it 😅

@@ -88,7 +89,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new SymfonyStyle($input, $output);

if (null === $twig = $this->getTwigEnvironment()) {
$io->error('The Twig environment needs to be set.');
$errorIo = $output instanceof ConsoleOutputInterface ? new SymfonyStyle($input, $output->getErrorOutput()) : $io;
$errorIo->error('The Twig environment needs to be set.');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd challenge this one in order to simply throw a \RuntimeException instead. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I've reverted a similar change in my previous PR thinking it was the same, but actually it's another place: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Command/DebugCommand.php#L90

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure 👍 but should it be done here?

Copy link
Contributor

@ogizanagi ogizanagi Nov 28, 2016

Choose a reason for hiding this comment

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

As it slightly changes the output and is done mainly in the aim to output it to stderr more straightforwardly, I'd say yes.

Copy link
Contributor

@ogizanagi ogizanagi Jan 7, 2017

Choose a reason for hiding this comment

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

The Twig Bridge DebugCommand update is still missing here, even in case the suggestion about throwing an exception instead is not considered. ^^

Copy link
Member Author

Choose a reason for hiding this comment

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

Both debug/lint commands have been updated :)

@chalasr
Copy link
Member Author

chalasr commented Nov 28, 2016

Having two places to discuss/review/merge about the same thing looks not simpler to me, as you wish.

@ogizanagi
Copy link
Contributor

Apply the patch then and I'll close mine.

@chalasr
Copy link
Member Author

chalasr commented Nov 28, 2016

Done 2af000a

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@nicolas-grekas nicolas-grekas added Feature and removed Bug labels Dec 6, 2016
@nicolas-grekas
Copy link
Member

👍

@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch 6 times, most recently from 8ddb044 to 6eaaf28 Compare January 6, 2017 21:42
@chalasr
Copy link
Member Author

chalasr commented Jan 6, 2017

Updated for using getErrorStyle() in the FrameworkBundle (as it requires the console to be ~3.3) and fixed the WebServerBundle commands.

@@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new SymfonyStyle($input, $output);

if (null === $twig = $this->getTwigEnvironment()) {
$io->error('The Twig environment needs to be set.');
$io->getErrorStyle()->error('The Twig environment needs to be set.');
Copy link
Member

Choose a reason for hiding this comment

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

This will fail when the bridge is used with older versions (before 3.3) of the Console component which is completely valid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted

@@ -62,11 +62,12 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted everywhere

Copy link
Member Author

@chalasr chalasr Jan 12, 2017

Choose a reason for hiding this comment

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

@xabbuh The framework now has a conflict for symfony/console: <3.3 so it should be fine

@@ -85,8 +85,9 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$errorIo = $io->getErrorStyle();
Copy link
Member

Choose a reason for hiding this comment

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

and the same also applies to the SecurityBundle

Copy link
Member Author

Choose a reason for hiding this comment

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

Would it work (and make sense) to add a conflict with older versions of the Console?

@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch 5 times, most recently from bebd602 to b64fe2d Compare January 8, 2017 10:37
@chalasr
Copy link
Member Author

chalasr commented Jan 8, 2017

Build failure unrelated (see #21198)

@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch from b64fe2d to 462a6f5 Compare January 10, 2017 17:16
@chalasr
Copy link
Member Author

chalasr commented Jan 10, 2017

Rebased, tests are green. This is ready

@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch 5 times, most recently from 1b327f5 to 201bb4a Compare January 12, 2017 17:33
@chalasr chalasr force-pushed the framework/use_stderr_in_commands branch from 201bb4a to 7b262d8 Compare January 12, 2017 20:28
@chalasr
Copy link
Member Author

chalasr commented Jan 30, 2017

ping

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

👍

@fabpot
Copy link
Member

fabpot commented Feb 19, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 7b262d8 into symfony:master Feb 19, 2017
fabpot added a commit that referenced this pull request Feb 19, 2017
…output (chalasr, ogizanagi)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle] Make use of stderr for non reliable output

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Built-in commands should make use of the proper outputs.
As a feature on master, considering that people may actually rely on stdout and the fact commands have been changed a lot since 2.7, I think it's not worth doing this change on lower branches.

Please see also #20586 which adds a `SymfonyStyle::getErrorStyle()` shortcut for easily switching to stderr.

Commits
-------

7b262d8 [FrameworkBundle] Use getErrorStyle() when relevant
9a3a568 Use stderr for some other commands
1ee48bf [FrameworkBundle] Make use of stderr for non reliable output
@chalasr chalasr deleted the framework/use_stderr_in_commands branch February 20, 2017 05:55
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants