Skip to content

-ErrorAction Ignore doesn't work for calling advanced functions #1759

@SteveL-MSFT

Description

@SteveL-MSFT
  1. Create a script with the following code:
function foo
{
    [CmdletBinding()]
    param()

process
{
    try
    {
        Write-Error 'boo'
    }
    finally { }
}

}

function bar
{
    foo -ErrorAction Ignore
}
  1. Dot-source that script to import the function definitions.
  2. Call the "bar" function.

Expected result:
Nothing (no output; no error--bar is calling foo with "-ErrorAction Ignore").

Actual result:
I get an error, and it's not even the one written by foo:

Write-Error : The value Ignore is not supported for an ActionPreference variable. The provided value should be used only as a value for a preference
parameter, and has been replaced by the default value. For more information, see the Help topic, "about_Preference_Variables."
At E:\temp\ps_ea_ignore_2.ps1:11 char:13
-             Write-Error 'boo'
-             ~~~~~~~~~~~~~~~~~
  - CategoryInfo          : NotSpecified: (:) [Write-Error], NotSupportedException
  - FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.WriteErrorCommand

Dan Thompson:
In addition to being annoying for straight-up calling advanced functions (you can't use "-ErrorAction Ignore" with them), this also hampers meta-programming (you can't do "& $someCmd -ErrorAction Ignore", because you might not know if $someCmd is an advanced function or not).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions