Skip to content

Fix unnecessary trimming of line resulting in incorrect indexi… - #11670

Merged
Travis Plunk (TravisEz13) merged 4 commits into
PowerShell:masterfrom
SteveL-MSFT:error-indent
Jan 30, 2020
Merged

Travis Plunk (TravisEz13) merged 4 commits into
PowerShell:masterfrom
SteveL-MSFT:error-indent

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Jan 24, 2020 •

Copy link
Copy Markdown
Member

PR Summary

After the switch to use InvocationInfo.PositionMessage instead of crafting equivalent, the use of Trim() caused a mismatch between the line of script with the error and the underlining line so the line of code to insert VT100 color can be out of bounds. The whitespace at the beginning of the line causes this issue because Trim() makes the highlight line too short (previously the script line would also be trimmed).

Also fixed an issue where it was splitting PositionMessage by + to get the individual parts, but the message itself can contain a + so using newline instead. This with the trim is what caused the index to be out of bounds as the line is now too short to insert the VT100 code to reset the color back.

In addition, switched all use of `n to [Environment]::Newline.

Finally, removed an extra newline in the rendering.

PR Context

Fix #11669

PR Checklist

replace `n with [environment]::newline
remove extra newline
@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jan 24, 2020
@iSazonov

Copy link
Copy Markdown
Collaborator

We have many issues with these helper functions. Maybe put them in a temp module? This can simplify debugging and fixing.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) which helpers are you referring to? The tests don't really have any helpers?

@iSazonov

Copy link
Copy Markdown
Collaborator

Steve Lee (@SteveL-MSFT) I mean the formatting functions like Show-Error and Get-ConciseViewPositionMessage.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All this code seems pretty fragile and relies on the format of the error message which could change at any time. There's not much we can do about other that to rethink the whole error presentation which is probably not something we should entertain at the moment.

@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) In 7.1, we'll have appropriate APIs for coloring/VT100, we can consider some refactoring then vs making a big change now

@TravisEz13 Travis Plunk (TravisEz13) changed the title fix unncessary trimming of line resulting in incorrect indexing fix unnecessary trimming of line resulting in incorrect indexing in errors Jan 30, 2020
@TravisEz13 Travis Plunk (TravisEz13) changed the title fix unnecessary trimming of line resulting in incorrect indexing in errors Fix unnecessary trimming of line resulting in incorrect indexi… Jan 30, 2020
@TravisEz13
Travis Plunk (TravisEz13) merged commit 66912b7 into PowerShell:master Jan 30, 2020
@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the error-indent branch January 30, 2020 21:12
@ghost

Copy link
Copy Markdown

🎉v7.0.0-rc.3 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Still some bugs in error formatting, indent somehow involved

7 participants