Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of CmdletBinding prevents ErrorAction from propagating #53

Closed
tomrowton-alk opened this issue May 10, 2023 · 5 comments
Closed

Lack of CmdletBinding prevents ErrorAction from propagating #53

tomrowton-alk opened this issue May 10, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@tomrowton-alk
Copy link

tomrowton-alk commented May 10, 2023

It seems that not having [CmdletBinding()] for the functions is preventing an explicitly passed -ErrorAction from propagating to child calls. For example, if I call Get-FeatureFlagConfigFromFile -jsonConfigPath $f -ErrorAction SilentlyContinue where $f is a path that does not exist, you will get a halting error; however, if I add [CmdletBinding()] to that function, the halting error moves to the child call Confirm-FeatureFlagConfig - and if I add [CmdletBinding()] to that function, then I get back $null like Get-FeatureFlagConfigFromFile code is written.

To reproduce:
Call $c = Get-FeatureFlagConfigFromFile -jsonConfigPath $f where $f is a path that does not exist
then
Call $c2 = Get-FeatureFlagConfigFromFile -jsonConfigPath $f -ErrorAction SilentlyContinue where $f is a path that does not exist

$c2 should be returned without outputting an error to the console, and be $null
I thought this was working in earlier tests, but trying it now, -ErrorAction is not being passed on.

I'm using version 2.1.0 of FeatureFlags in Powershell 5 with the following $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.2673
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.2673
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
@lupino3 lupino3 self-assigned this May 10, 2023
@lupino3 lupino3 added the bug Something isn't working label May 10, 2023
@lupino3
Copy link
Member

lupino3 commented May 10, 2023

Thanks for the bug report! We should indeed have CmdletBinding() calls.

I'll add those, and see if I can use your repro instructions as a unit test.
Thanks!

lupino3 added a commit that referenced this issue May 10, 2023
This will allow, among other things, propagation of the ErrorAction
parameter, and correctly inhibit output when needed.

This behavior is tested in a new test for Get-FeatureFlagConfigFromFile.

Fixes Lack of CmdletBinding prevents ErrorAction from propagating #53
lupino3 added a commit that referenced this issue May 11, 2023
This will allow, among other things, propagation of the ErrorAction
parameter, and correctly inhibit output when needed.

This behavior is tested in a new test for Get-FeatureFlagConfigFromFile.

Fixes Lack of CmdletBinding prevents ErrorAction from propagating #53
@lupino3
Copy link
Member

lupino3 commented May 11, 2023

Should be fixed. Thanks for the bug report! I'll try to do a release today.

@lupino3 lupino3 closed this as completed May 11, 2023
@lupino3
Copy link
Member

lupino3 commented May 12, 2023

The fix is released in version 2.1.1: https://github.com/microsoft/PowerShell-FeatureFlags/releases/tag/2.1.1.

@tomrowton-alk
Copy link
Author

Thank you very much!

@tomrowton-alk
Copy link
Author

Verified working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants