PoshCode / ErrorView

An attempt to simplify and customize error views
MIT License
13 stars 0 forks source link

Bring back red errors in PowerShell 7.4+ #1

Open o-o00o-o opened 1 year ago

o-o00o-o commented 1 year ago

FullMode is exactly what is needed for me all the time - full stack trace, great for logs.

However when using it interactively I find that it is harder to spot when errors happen.

Is there any way that the colour can be set? I actually would prefer if the whole error is in normal white but if there was a header/footer row that was in red to show the user that things didn't go according to plan

o-o00o-o commented 1 year ago

I've had a play with this locally and changed the ErrorView.ps1xml to

<![CDATA[
                    if ($formatter = Get-Command "ConvertTo-$($global:ErrorView -replace "View")ErrorView" -ListImported -ErrorAction Ignore -ParameterName InputObject -ParameterType [System.Management.Automation.ErrorRecord]) {
                      write-host "Error $([string]::new('━', 80))" -ForegroundColor Red
                      &@($formatter)[0] $_
                    } else {
                      ConvertTo-NormalErrorView $_
                    }
                  ]]>

and this produces quite a nice output

image

any chance this could be included in the distribution so everyone can get this?

Jaykul commented 2 days ago

Yeah, apparently, we need to color our own errors now.

That's going to make it really complicated to do this compatibly for old versions of PowerShell.

It used to be the case (you can test this in PS5) that all text we wrote here would be red. Apparently, they've changed this in the latest PowerShell release.