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

Write CLI errors to stderr #2317

Merged
merged 8 commits into from
Nov 18, 2024
Merged

Conversation

InvisibleSmiley
Copy link
Contributor

@InvisibleSmiley InvisibleSmiley commented Oct 16, 2024

Fixes #2270.

In the end I chose to copy/adapt OutputStyle::getErrorOutput as a new protected method on the abstract command rather than using SymfonyStyle because:

  1. creating SymfonyStyle requires both $input and $output, but some existing methods only receive $output
  2. SymfonyStyle behaves differently than the plain OutputStyle, which might introduce new issues

I also fixed the exit code for the case where no aliases exist, applying the rule "error output -> exit code 1".

@InvisibleSmiley InvisibleSmiley changed the title Issue-2270 Fix #2270 Oct 16, 2024
@InvisibleSmiley InvisibleSmiley changed the title Fix #2270 Let commands write errors to STDERR if available (fix issue 2270) Oct 16, 2024
@@ -204,7 +204,7 @@ public function connect(): void
*/
public static function getSuffix(array $options): string
{
if ($options['name'] === self::MEMORY) {
if (($options['name'] ?? '') === self::MEMORY) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This produced a notice when running tests (with error_reporting = E_ALL in php.ini)

@@ -4,6 +4,12 @@

<rule ref="CakePHP"/>

<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests do not contain all necessary imports (uses) right now because without this PHPCS will complain.
I added the missing imports to MigrateTest and will leave the rest for someone else to clean up.

@MasterOdin MasterOdin changed the title Let commands write errors to STDERR if available (fix issue 2270) Write CLI errors to stderr Nov 18, 2024
@MasterOdin MasterOdin merged commit 411d94a into cakephp:0.x Nov 18, 2024
14 checks passed
@MasterOdin
Copy link
Member

Thanks for your PR!

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

Successfully merging this pull request may close these issues.

(At least) Non-interactive commands should write errors to STDERR
3 participants