Saturday, December 10, 2016

PowerShell v2 ErrorView CategoryView

,
Tiny comment, but, a useful one. Lets say you work in shell a lot and you get sick of having your coworkers harass you about all that red on your screen. You could change the colors, but, that would be too easy. Instead, you want a less chatty error message. Well, then, my friend, it sounds like you need CategoryView.  From an old PowerShell blog post:
$ERRORVIEW="CATEGORYVIEW"
I saw this option:
$ErrorView = "CategoryView"
Hmmm, new to me. Exactly what does that terse little command do. Lets break something and find out.
1/0
Yeah, that worked.
Attempted to divide by zero.
At line:1 char:3
+ 1/ <<<< 0
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RuntimeException
Now, lets change our $ErrorView to "CategoryView".
$ErrorView = CategoryView
and blow up more stuff:
1/0
Well, much less shrapnel:
NotSpecified: (:) [], ParentContainsErrorRecordException
In essence, CategoryView strips out a lot of the extra details and simply returns the CategoryInfo of the ErrorRecord. If you start playing about with the Debug cmdlets you will see this in a lot of output. Now you can know what its looking for.

Ok, nothing revolutionary here, but, good to know about. To reset it to the default simply $nullilfy the variable:
$ErrorView = $null

0 comments to “PowerShell v2 ErrorView CategoryView”

Post a Comment

 

Computer Info Copyright © 2016 -- Powered by Blogger