Repository navigation
Closed
Labels
Breaking-Changebreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionResolution-FixedThe issue is fixed.WG-Enginecore 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
Reacted by Michael Klement, Rob Emery and Balázs Orbán
Metadata
Metadata
Assignees
Labels
Breaking-Changebreaking change that may affect usersCommittee-ReviewedPS-Committee has reviewed this and made a decisionResolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime
Activity
joeyaiello commentedon May 25, 2017
This is a breaking change that we'd need to review, but if we're going to take it, there's the code, and we should do it sooner rather than later.
SteveL-MSFT commentedon May 31, 2017
@PowerShell/powershell-committee it appears
-Debugalso has the same issue. Committee agrees that we should fix this so that-ErrorActionworks correctly and not overridden by-Debugor-Verbose, but Jason Shirk (@lzybkr) would like to think about the implications of this changemintsoft commentedon Jun 2, 2017
We just ran into this bug too; +1 for changing it to respect the
$ErrorActionPreferencejoeyaiello commentedon Oct 10, 2017
Jason Shirk (@lzybkr) couldn't come up with anything per our last conversation on this one back in July-ish. We should implement the fix.
Honestly, though, this is a small enough one that I might feel okay pushing it out if we have to.
WernerMairl commentedon Dec 7, 2017
👍👍
a lot of unexpected behavior (without finding the reason) that i found in the last year should be solved with this, THANK YOU!