Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

-Verbose Changes (downgrades) the Error Behaviour #2247

Copy link
Copy link
@timker

Description

@timker
Issue body actions

-Verbose changes (downgrades) the Error Action from a Stop to Continue. This is undocumented and confusing.

Steps to reproduce

Run this script

$ErrorActionPreference = "Stop"
$VerbosePreference = "continue"

#safely creating a file for first run
if(-Not (Test-Path test.txt))
{
    new-item test.txt  -Verbose 
}

#create the same file
new-item test.txt  -Verbose
Write-output 'This should not output because ErrorActionPreference is set to STOP'


new-item test.txt 
Write-output 'This should never output because of the error above, and it doesn't'

Expected behavior

'This should not output because ErrorActionPreference is set to STOP', should not output

Actual behavior

'This should not output because ErrorActionPreference is set to STOP' is output

Bug Location

MshCommandRuntime.cs
internal ActionPreference ErrorAction
if (Verbose)
return ActionPreference.Continue;
doesn't will downgrade a Stop

Proposed Solution

                if (!_isErrorActionPreferenceCached)
                {
                    bool defaultUsed = false;
                    _errorAction = Context.GetEnumPreference<ActionPreference>(SpecialVariables.ErrorActionPreferenceVarPath, _errorAction, out defaultUsed);

                    //Verbose should upgrade communication preferences, but not downgrade ErrorAction behavioural preferences    
                    if (Verbose)
                    {
                        // don't downgrade preferences 
                        if (!(_errorAction == ActionPreference.Stop || _errorAction == ActionPreference.Suspend))
                        {
                            _errorAction = ActionPreference.Continue;
                        }
                    }

                    _isErrorActionPreferenceCached = true;
                }

Environment data

Major Minor Patch Label
----- ----- ----- -----
   6     0     0 alpha
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Breaking-Changebreaking change that may affect usersbreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionPS-Committee has reviewed this and made a decisionResolution-FixedThe issue is fixed.The issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.