Skip to content

Defining the $ErrorView preference variable in the current scope does not take effect (only in parent scope) #3645

@mklement0

Description

@mklement0

Preference variables generally take effect in the scope in which they're defined, which appears not be the case for $ErrorView, which only honors it in an ancestral scope:

Steps to reproduce

& { Set-Variable -Scope 0 VerbosePreference Continue; Write-Verbose 'I will display.' }
& { Set-Variable -Scope 0 ErrorView CategoryView; Get-Item /NoSuchItem }
& { Set-Variable -Scope 1 ErrorView CategoryView; Get-Item /NoSuchItem }

Note: To re-run the test, start a new session, because the last command sets $ErrorView in the global scope.

Expected behavior

I will display.
ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException
ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException

Actual behavior

I will display.
Get-Item : Cannot find path '/NoSuchItem' because it does not exist.
At line:1 char:54
+ ... t-Variable -Scope 0 ErrorView CategorizedView; Get-Item /NoSuchItem }
+                                                    ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException

Setting $ErrorView in the same scope as the failing Get-Item command didn't take effect - contrast this with the $VerbosePreference variable.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions