8000 Fix unnecessary trimming of line resulting in incorrect indexi… by SteveL-MSFT · Pull Request #11670 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@SteveL-MSFT
Copy link
Member
@SteveL-MSFT SteveL-MSFT commented Jan 24, 2020

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 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
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
Member Author

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

@iSazonov
Copy link
Collaborator

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

Copy link
Collaborator
@JamesWTruher JamesWTruher left a comment

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
Member Author

@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 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 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 TravisEz13 merged commit 66912b7 into PowerShell:master Jan 30, 2020
@SteveL-MSFT SteveL-MSFT deleted the error-indent branch January 30, 2020 21:12
@daxian-dbw daxian-dbw modified the milestones: GA-consider, GA-approved Jan 31, 2020
@TravisEz13 TravisEz13 modified the milestones: GA-approved, 7.0.0 Feb 8, 2020
adityapatwardhan pushed a commit to adityapatwardhan/PowerShell that referenced this pull request Feb 18, 2020
@ghost
Copy link
ghost commented Feb 21, 2020

🎉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

0