[Console] Fix Multi-Line Error Message Format#7164
Merged
samsonasik merged 1 commit intorectorphp:mainfrom Aug 22, 2025
Merged
Conversation
Member
|
Thank you @FeBe95 |
Member
|
@FeBe95 could you add more fix on |
Contributor
Author
Will do 👍 |
This was referenced Aug 25, 2025
Contributor
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes rectorphp/rector#9323.
Why is this necessary?
The
PHP_EOLconstant is used throughout the Rector source code to add newlines to error messages, that are forwarded to Symfony's Console component. On Windows,PHP_EOLresolves to\r\n. However, Symfony's console output formatter does not support\r\nline breaks. After calculating the width of the terminal window, it adds\ncharacters to the appropriate positions in the given message and splits the resulting string using\nas a separator. This leaves the affected lines with a trailing\rcharacter, which breaks the console output.Example
Let's take a look at the linked issue above as an example.
\ncharacters at the appropriate positions where the message should be cut. For a rather small terminal window, the resulting string could look like this:\n, which results in these lines:\rcharacter in line 3 resets the cursor to the beginning of the line while outputting. Then, the output formatter prints the red padding characters (17x in this case). These characters overwrite the first 17 existing characters of the current line, including the beginning of the actual error message. The output is now broken.Solution
Sanitize all
\r\noccurrences to simple\ncharacters:Screenshots
Below are some more screenshots, showing the "before" and "after" of the reported issue, using the original examples.
Wide
Narrow