mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix ConciseView where error message is wider than window width and doesn't have whitespace (#11880)
This commit is contained in:
+15
-9
@@ -1151,12 +1151,10 @@ namespace System.Management.Automation.Runspaces
|
||||
|
||||
# replace newlines in message so it lines up correct
|
||||
$message = $message.Replace($newline, ' ').Replace(""`t"", ' ')
|
||||
try {
|
||||
$windowWidth = [Console]::WindowWidth
|
||||
}
|
||||
catch {
|
||||
# fails if there is no console
|
||||
$windowWidth = 120
|
||||
|
||||
$windowWidth = 120
|
||||
if ($Host.UI.RawUI -ne $null) {
|
||||
$windowWidth = $Host.UI.RawUI.WindowSize.Width
|
||||
}
|
||||
|
||||
if ($windowWidth -gt 0 -and ($message.Length - $prefixVTLength) -gt $windowWidth) {
|
||||
@@ -1168,9 +1166,17 @@ namespace System.Management.Automation.Runspaces
|
||||
while (($remainingMessage.Length + $prefixLength) -gt $windowWidth) {
|
||||
$subMessage = $prefix + $remainingMessage
|
||||
$substring = Get-TruncatedString -string $subMessage -length ($windowWidth + $prefixVtLength)
|
||||
$null = $sb.Append($substring)
|
||||
$null = $sb.Append($newline)
|
||||
$remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim()
|
||||
|
||||
if ($substring.Length - $prefix.Length -gt 0)
|
||||
{
|
||||
$null = $sb.Append($substring)
|
||||
$null = $sb.Append($newline)
|
||||
$remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim()
|
||||
}
|
||||
else
|
||||
{
|
||||
break
|
||||
}
|
||||
}
|
||||
$null = $sb.Append($prefix + $remainingMessage.Trim())
|
||||
$message = $sb.ToString()
|
||||
|
||||
@@ -87,6 +87,18 @@ Describe 'Tests for $ErrorView' -Tag CI {
|
||||
# validate line number is shown
|
||||
$e | Should -BeLike '* 2 *'
|
||||
}
|
||||
|
||||
It "Long exception message gets rendered" {
|
||||
|
||||
$msg = "1234567890"
|
||||
while ($msg.Length -le $Host.UI.RawUI.WindowSize.Width)
|
||||
{
|
||||
$msg += $msg
|
||||
}
|
||||
|
||||
$e = { throw "$msg" } | Should -Throw $msg -PassThru | Out-String
|
||||
$e | Should -BeLike "*$msg*"
|
||||
}
|
||||
}
|
||||
|
||||
Context 'NormalView tests' {
|
||||
|
||||
Reference in New Issue
Block a user