When $ErrorView = ConciseView (default), an error output from within a module is stripped of new lines, generating weird looking output. #24108
Open
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Opening this on behalf of a customer.
- Create a simple dummy PowerShell module (e.g: error-test.psm1), containing this:
Function Test-Error {
$errorMessage = "Line1`r`nLine2`r`n"
Write-Error -Message "`r`n$errorMessage"
}
Function Test-ErrorWrapper {
Test-Error
}
- Import the module in your current PowerShell session:
Import-Module <path to>\error-test.psm1
- Run the
Test-Error
function, everything works as expected. - Run the
Test-ErrorWrapper
(just calling the other function) & the error message is displayed without any line breaks.
Note: if you change $ErrorView
to NormalView
then the line breaks are displayed as expected, along with the "full error details".
Expected behavior
Test-Error displays the message as intended.
PS C:\> Test-Error
Test-Error:
Line1
Line2
Actual behavior
Test-ErrorWrapper displays the message without the line breaks, everything on a single line.
PS C:\> Test-ErrorWrapper
Test-Error: Line1 Line2
Error details
No response
Environment data
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.4
PSEdition Core
GitCommitId 7.4.4
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
When $ErrorView
is ConciseView
(by default in PowerShell 7+), line breaks are missing/removed:
When $ErrorView
is set to NormalView
, the line breaks are there & the message is displayed as intended, along with the "full error details".