-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
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
Milestone
Description
-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
mklement0, mintsoft and orbanbalage
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