Skip to content

$ErrorView = 'NormalView' leaves the console in Error color after rendering an ErrorRecord #17885

@daxian-dbw

Description

@daxian-dbw

Prerequisites

Steps to reproduce

Repro steps:

  1. Open the latest PowerShell preview.7, and make sure using the default prompt
  2. Run $ErrorView = 'NormalView'
  3. Run Write-Error 'error'

This is a bug introduced by #17705.
The Cosnole.ForegroundColor and Console.BackgroundColor were changed but never set back after writing out the message.

if ($ErrorView -ne 'ConciseView' -and $null -ne $host.PrivateData) {
if ($null -ne $host.PrivateData.ErrorForegroundColor) {
[Console]::ForegroundColor = $host.PrivateData.ErrorForegroundColor
}
if ($null -ne $host.PrivateData.ErrorBackgroundColor) {
[Console]::BackgroundColor = $host.PrivateData.ErrorBackgroundColor
}
}

Expected behavior

The prompt after executing `Write-Error 'error'` doesn't have the color changed

Actual behavior

The prompt gets changed to the error color

Error details

N/A

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0-preview.7
PSEdition                      Core
GitCommitId                    7.3.0-preview.7
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Metadata

Metadata

Assignees

Labels

Resolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions