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

Make sure ErrorRecords go to Error stream #1201

Conversation

TylerLeonhardt
Copy link
Member

@daxian-dbw found a strange behavior in the Console's PSHost where empty lines are skipped in WriteErrorLine.

He also discovered that errors were not going into the Error stream unless they have the WriteStream property set to Error.. which sadly can only be done via reflection.

This leverages that so that errors are printed out correctly instead of with this ugly line:
MicrosoftTeams-image (2)

Also actually uses PowerShell to format parse errors correctly.


this.WriteError(message);
var psObject = PSObject.AsPSObject(e.ErrorRecord);
s_writeStreamProperty.SetValue(psObject, s_errorStreamValue);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might also be possible to bake these two reflection values into a closed delegate, but it's not necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

talked offline... since the Enum type is not public, we'll defer this for now as it's more work than it's worth.

@TylerLeonhardt
Copy link
Member Author

I've added a bit more logic to make sure that pre-7 it's also being added to the ErrorStream. This is important for the legacy console experience which would render the errors as white instead of red without the note property.

}
else
{
var note = new PSNoteProperty("writeErrorStream", true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
var note = new PSNoteProperty("writeErrorStream", true);
var note = new PSNoteProperty("WriteErrorStream", true);

Copy link
Member Author

Choose a reason for hiding this comment

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

I got that from PowerShell but since it seems to be case insensitive I can make this change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

May as well use what PowerShell uses. Strange they did it that way

@TylerLeonhardt
Copy link
Member Author

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 1
           

See the complete overview on Codacy

@TylerLeonhardt TylerLeonhardt merged commit 86d7804 into PowerShell:master Feb 20, 2020
@TylerLeonhardt TylerLeonhardt deleted the ErrorRecords-go-to-Error-stream branch February 20, 2020 20:50
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.

None yet

2 participants