Repository navigation
Route deprecated-alias warnings and writer errors to stderr - #77
Merged
Merged
Conversation
Illuminate\Console\Command::run() wraps the terminal output in an OutputStyle before initialize() and handle() see it, and OutputStyle is not a ConsoleOutputInterface. The instanceof checks in WarnsOnDeprecatedAlias and ConsoleWriter therefore never matched inside a command, so the alias warning became the first line of stdout and ConsoleWriter error(), danger() and toStderr() wrote to stdout too. Both now resolve the error stream through Tools\Support\ErrorOutput, which unwraps the style first. Outputs without an error stream, such as the buffer Artisan::call() uses, are unchanged. The new test drives the real Command::run() path with an output that keeps stdout and stderr apart; it fails on the previous code.
imanimanyara
added a commit
to laranail/package-scaffolder
that referenced
this pull request
Oct 7, 2026
) laranail/console#77 makes the shared WarnsOnDeprecatedAlias see through Laravel's OutputStyle, so on a terminal the bare-alias warning goes to stderr rather than leading stdout. The installation guide and the Unreleased CHANGELOG entry now describe that, and say v0.1.5 still puts the line on stdout. DeprecatedAliasTest no longer leaves the stream open: it pins stderr when the installed console carries the fix and stdout when it does not, so it asserts the right stream on both sides of the upgrade and fails if the fixed release regresses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
WarnsOnDeprecatedAliasis documented to print its warning on stderr, so piped output is unchanged. It printed on stdout.ConsoleWriter'serror(),danger()andtoStderr()had the same defect whenever the writer came from a command.Root cause
Illuminate\Console\Command::run()wraps the output it receives in anIlluminate\Console\OutputStylebefore Symfony callsinitialize()orhandle().OutputStyledoes not implementConsoleOutputInterface, so$output instanceof ConsoleOutputInterfacewas false for every output a command sees, and both call sites fell back to stdout. Found in review of laranail/package-scaffolder#28: runningmodule:listagainst an output with a separate error stream putDeprecated: [module:list] is a deprecated alias...on the first line of stdout, with stderr empty.Fix
Tools\Support\ErrorOutput::of()(internal): unwraps anOutputStylewithgetOutput(), then returnsgetErrorOutput()when the inner output is aConsoleOutputInterface, otherwise the original output.WarnsOnDeprecatedAlias::initialize()andConsoleWriter(status()andstream()) resolve stderr through it.BufferedOutput, asArtisan::call()uses) gets the line as before, soArtisan::output()still contains the warning.Behaviour change
On a real terminal the alias warning and ConsoleWriter errors move from stdout to stderr, which is what the docs already said. Recorded under
[Unreleased]/ Fixed in the CHANGELOG.Tests
tests/Tools/Unit/Commands/StderrRoutingTest.phpruns commands through the realCommand::run()path with an output that keeps stdout and stderr in separate streams:handledon stdout;consoleWriter()->error()and->toStderr()reach stderr.All three fail on the previous code (the warning and error lines appear on stdout) and pass with this change. Local: pest 561 passed, phpstan no errors, rector and pint clean.