| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1151,12 +1151,10 @@ function Get-ConciseViewPositionMessage { | |||
| 1151 | 1151 | ||
| 1152 | 1152 | # replace newlines in message so it lines up correct | |
| 1153 | 1153 | $message = $message.Replace($newline, ' ').Replace(""`t"", ' ') | |
| 1154 | - try { | ||
| 1155 | - $windowWidth = [Console]::WindowWidth | ||
| 1156 | - } | ||
| 1157 | - catch { | ||
| 1158 | - # fails if there is no console | ||
| 1159 | - $windowWidth = 120 | ||
| 1154 | + | ||
| 1155 | + $windowWidth = 120 | ||
| 1156 | + if ($Host.UI.RawUI -ne $null) { | ||
| 1157 | + $windowWidth = $Host.UI.RawUI.WindowSize.Width | ||
| 1160 | 1158 | } | |
| 1161 | 1159 | ||
| 1162 | 1160 | if ($windowWidth -gt 0 -and ($message.Length - $prefixVTLength) -gt $windowWidth) { | |
@@ -1168,9 +1166,17 @@ function Get-ConciseViewPositionMessage { | |||
| 1168 | 1166 | while (($remainingMessage.Length + $prefixLength) -gt $windowWidth) { | |
| 1169 | 1167 | $subMessage = $prefix + $remainingMessage | |
| 1170 | 1168 | $substring = Get-TruncatedString -string $subMessage -length ($windowWidth + $prefixVtLength) | |
| 1171 | - $null = $sb.Append($substring) | ||
| 1172 | - $null = $sb.Append($newline) | ||
| 1173 | - $remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim() | ||
| 1169 | + | ||
| 1170 | + if ($substring.Length - $prefix.Length -gt 0) | ||
| 1171 | + { | ||
| 1172 | + $null = $sb.Append($substring) | ||
| 1173 | + $null = $sb.Append($newline) | ||
| 1174 | + $remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim() | ||
| 1175 | + } | ||
| 1176 | + else | ||
| 1177 | + { | ||
| 1178 | + break | ||
| 1179 | + } | ||
| 1174 | 1180 | } | |
| 1175 | 1181 | $null = $sb.Append($prefix + $remainingMessage.Trim()) | |
| 1176 | 1182 | $message = $sb.ToString() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,18 @@ Describe 'Tests for $ErrorView' -Tag CI { | |||
| 87 | 87 | # validate line number is shown | |
| 88 | 88 | $e | Should -BeLike '* 2 *' | |
| 89 | 89 | } | |
| 90 | + | ||
| 91 | + It "Long exception message gets rendered" { | ||
| 92 | + | ||
| 93 | + $msg = "1234567890" | ||
| 94 | + while ($msg.Length -le $Host.UI.RawUI.WindowSize.Width) | ||
| 95 | + { | ||
| 96 | + $msg += $msg | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + $e = { throw "$msg" } | Should -Throw $msg -PassThru | Out-String | ||
| 100 | + $e | Should -BeLike "*$msg*" | ||
| 101 | + } | ||
| 90 | 102 | } | |
| 91 | 103 | ||
| 92 | 104 | Context 'NormalView tests' { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments