| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 79f9494 commit fe8744d
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,15 +147,14 @@ internal object Transform(EngineIntrinsics engineIntrinsics, object inputData, b | |||
| 147 | 147 | // Note - this is duplicated in ExecutionContext.cs as parameter binding for script cmdlets can avoid this code path. | |
| 148 | 148 | if ((!bindingScriptCmdlet) && (!bindingParameters)) | |
| 149 | 149 | { | |
| 150 | - // ActionPreference of Suspend is not supported as a preference variable. We can only block "Suspend" | ||
| 151 | - // during variable assignment (here) - "Ignore" is blocked during variable retrieval. | ||
| 150 | + // ActionPreference.Suspend is reserved for future use and is not supported as a preference variable. | ||
| 152 | 151 | if (_convertTypes[i] == typeof(ActionPreference)) | |
| 153 | 152 | { | |
| 154 | 153 | ActionPreference resultPreference = (ActionPreference)result; | |
| 155 | 154 | ||
| 156 | 155 | if (resultPreference == ActionPreference.Suspend) | |
| 157 | 156 | { | |
| 158 | - throw new PSInvalidCastException("InvalidActionPreference", null, ErrorPackage.UnsupportedPreferenceVariable, resultPreference); | ||
| 157 | + throw new PSInvalidCastException("InvalidActionPreference", null, ErrorPackage.ActionPreferenceReservedForFutureUseError, resultPreference); | ||
| 159 | 158 | } | |
| 160 | 159 | } | |
| 161 | 160 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,7 +291,7 @@ public enum ActionPreference | |||
| 291 | 291 | /// <summary>Ignore the event completely (not even logging it to the target stream)</summary> | |
| 292 | 292 | Ignore = 4, | |
| 293 | 293 | ||
| 294 | - /// <summary>Suspend the command for further diagnosis. Supported only for workflows.</summary> | ||
| 294 | + /// <summary>Reserved for future use.</summary> | ||
| 295 | 295 | Suspend = 5, | |
| 296 | 296 | ||
| 297 | 297 | /// <summary>Enter the debugger.</summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -573,18 +573,9 @@ internal T GetEnumPreference<T>(VariablePath preferenceVariablePath, T defaultPr | |||
| 573 | 573 | object val = EngineSessionState.GetVariableValue(preferenceVariablePath, out _, out _); | |
| 574 | 574 | if (val is T) | |
| 575 | 575 | { | |
| 576 | - // We don't want to support "Ignore" as action preferences, as it leads to bad | ||
| 577 | - // scripting habits. They are only supported as cmdlet overrides. | ||
| 578 | - if (val is ActionPreference) | ||
| 576 | + if (val is ActionPreference actionPreferenceValue) | ||
| 579 | 577 | { | |
| 580 | - ActionPreference preference = (ActionPreference)val; | ||
| 581 | - if ((preference == ActionPreference.Ignore) || (preference == ActionPreference.Suspend)) | ||
| 582 | - { | ||
| 583 | - // Reset the variable value | ||
| 584 | - EngineSessionState.SetVariableValue(preferenceVariablePath.UserPath, defaultPref); | ||
| 585 | - string message = StringUtil.Format(ErrorPackage.UnsupportedPreferenceError, preference); | ||
| 586 | - throw new NotSupportedException(message); | ||
| 587 | - } | ||
| 578 | + CheckActionPreference(preferenceVariablePath, actionPreferenceValue, defaultPref); | ||
| 588 | 579 | } | |
| 589 | 580 | ||
| 590 | 581 | T convertedResult = (T)val; | |
@@ -611,6 +602,11 @@ internal T GetEnumPreference<T>(VariablePath preferenceVariablePath, T defaultPr | |||
| 611 | 602 | result = (T)PSObject.Base(val); | |
| 612 | 603 | defaultUsed = false; | |
| 613 | 604 | } | |
| 605 | + | ||
| 606 | + if (result is ActionPreference actionPreferenceValue) | ||
| 607 | + { | ||
| 608 | + CheckActionPreference(preferenceVariablePath, actionPreferenceValue, defaultPref); | ||
| 609 | + } | ||
| 614 | 610 | } | |
| 615 | 611 | catch (InvalidCastException) | |
| 616 | 612 | { | |
@@ -625,6 +621,18 @@ internal T GetEnumPreference<T>(VariablePath preferenceVariablePath, T defaultPr | |||
| 625 | 621 | return result; | |
| 626 | 622 | } | |
| 627 | 623 | ||
| 624 | + private void CheckActionPreference(VariablePath preferenceVariablePath, ActionPreference preference, object defaultValue) | ||
| 625 | + { | ||
| 626 | + if (preference == ActionPreference.Suspend) | ||
| 627 | + { | ||
| 628 | + // ActionPreference.Suspend is reserved for future use. When it is used, reset | ||
| 629 | + // the variable to its default. | ||
| 630 | + string message = StringUtil.Format(ErrorPackage.ReservedActionPreferenceReplacedError, preference, preferenceVariablePath.UserPath, defaultValue); | ||
| 631 | + EngineSessionState.SetVariable(preferenceVariablePath, defaultValue, true, CommandOrigin.Internal); | ||
| 632 | + throw new NotSupportedException(message); | ||
| 633 | + } | ||
| 634 | + } | ||
| 635 | + | ||
| 628 | 636 | /// <summary> | |
| 629 | 637 | /// Same as GetEnumPreference, but for boolean values. | |
| 630 | 638 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3009,6 +3009,11 @@ internal ActionPreference DebugPreference | |||
| 3009 | 3009 | ||
| 3010 | 3010 | set | |
| 3011 | 3011 | { | |
| 3012 | + if (value == ActionPreference.Suspend) | ||
| 3013 | + { | ||
| 3014 | + throw PSTraceSource.NewNotSupportedException(ErrorPackage.ActionPreferenceReservedForFutureUseError, value); | ||
| 3015 | + } | ||
| 3016 | + | ||
| 3012 | 3017 | _debugPreference = value; | |
| 3013 | 3018 | _isDebugPreferenceSet = true; | |
| 3014 | 3019 | } | |
@@ -3098,7 +3103,7 @@ internal ActionPreference WarningPreference | |||
| 3098 | 3103 | { | |
| 3099 | 3104 | if (value == ActionPreference.Suspend) | |
| 3100 | 3105 | { | |
| 3101 | - throw PSTraceSource.NewNotSupportedException(ErrorPackage.SuspendActionPreferenceErrorActionOnly); | ||
| 3106 | + throw PSTraceSource.NewNotSupportedException(ErrorPackage.ActionPreferenceReservedForFutureUseError, value); | ||
| 3102 | 3107 | } | |
| 3103 | 3108 | ||
| 3104 | 3109 | _warningPreference = value; | |
@@ -3268,7 +3273,7 @@ internal ActionPreference ErrorAction | |||
| 3268 | 3273 | { | |
| 3269 | 3274 | if (value == ActionPreference.Suspend) | |
| 3270 | 3275 | { | |
| 3271 | - throw PSTraceSource.NewNotSupportedException(ErrorPackage.SuspendActionPreferenceSupportedOnlyOnWorkflow); | ||
| 3276 | + throw PSTraceSource.NewNotSupportedException(ErrorPackage.ActionPreferenceReservedForFutureUseError, value); | ||
| 3272 | 3277 | } | |
| 3273 | 3278 | ||
| 3274 | 3279 | _errorAction = value; | |
@@ -3301,6 +3306,11 @@ internal ActionPreference ProgressPreference | |||
| 3301 | 3306 | ||
| 3302 | 3307 | set | |
| 3303 | 3308 | { | |
| 3309 | + if (value == ActionPreference.Suspend) | ||
| 3310 | + { | ||
| 3311 | + throw PSTraceSource.NewNotSupportedException(ErrorPackage.ActionPreferenceReservedForFutureUseError, value); | ||
| 3312 | + } | ||
| 3313 | + | ||
| 3304 | 3314 | _progressPreference = value; | |
| 3305 | 3315 | _isProgressPreferenceSet = true; | |
| 3306 | 3316 | } | |
@@ -3335,7 +3345,7 @@ internal ActionPreference InformationPreference | |||
| 3335 | 3345 | { | |
| 3336 | 3346 | if (value == ActionPreference.Suspend) | |
| 3337 | 3347 | { | |
| 3338 | - throw PSTraceSource.NewNotSupportedException(ErrorPackage.SuspendActionPreferenceErrorActionOnly); | ||
| 3348 | + throw PSTraceSource.NewNotSupportedException(ErrorPackage.ActionPreferenceReservedForFutureUseError, value); | ||
| 3339 | 3349 | } | |
| 3340 | 3350 | ||
| 3341 | 3351 | _informationPreference = value; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -126,18 +126,13 @@ | |||
| 126 | 126 | <data name="RedirectedException" xml:space="preserve"> | |
| 127 | 127 | <value>Object "{0}" is reported as an error.</value> | |
| 128 | 128 | </data> | |
| 129 | - <data name="SuspendActionPreferenceErrorActionOnly" xml:space="preserve"> | ||
| 130 | - <value>The action preference of "Suspend" is supported only for ErrorAction.</value> | ||
| 131 | - <comment>"Suspend" and ErrorAction should not be localized</comment> | ||
| 132 | - </data> | ||
| 133 | - <data name="SuspendActionPreferenceSupportedOnlyOnWorkflow" xml:space="preserve"> | ||
| 134 | - <value>The error action preference of "Suspend" is supported only on workflows.</value> | ||
| 135 | - <comment>"Suspend" should not be localized - it is a literal.</comment> | ||
| 136 | - </data> | ||
| 137 | 129 | <data name="UnsupportedPreferenceError" xml:space="preserve"> | |
| 138 | 130 | <value>The value {0} 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."</value> | |
| 139 | 131 | </data> | |
| 140 | - <data name="UnsupportedPreferenceVariable" xml:space="preserve"> | ||
| 141 | - <value>The value {0} is not supported for an ActionPreference variable. The provided value should be used only as a value for a preference parameter. For more information, see the Help topic, "about_Preference_Variables."</value> | ||
| 132 | + <data name="ActionPreferenceReservedForFutureUseError" xml:space="preserve"> | ||
| 133 | + <value>The {0} ActionPreference value is reserved for future use and is not supported at this time. For more information about preference variables, see the Help topic, "about_Preference_Variables."</value> | ||
| 134 | + </data> | ||
| 135 | + <data name="ReservedActionPreferenceReplacedError" xml:space="preserve"> | ||
| 136 | + <value>The {0} ActionPreference value is reserved for future use and is not supported at this time. It has been replaced in your {1} variable by the default value of {2}. For more information about preference variables, see the Help topic, "about_Preference_Variables."</value> | ||
| 142 | 137 | </data> | |
| 143 | 138 | </root> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments