-
Notifications
You must be signed in to change notification settings - Fork 187
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
Exported functions not behaving correctly with -ErrorAction SilentlyContinue #409
Comments
Get-GitHubTeam -TeamName NonExistentTeam -ea 0
returns all teams instead of empty set.
Thanks for bringing this issue to my attention, @petervandivier! From the
From the
Given that, the expectation would be that there would be no behavior difference when function foo
{
[CmdletBinding()]
param()
throw "error"
write-host "I shouldn't see this"
}
# Just run it
foo
# results in this:
<#
Line |
3 | throw "error"
| ~~~~~~~~~~~~~
| error
#>
# But if I run it with -ErrorAction SilentlyContinue ...
foo -ErrorAction SilentlyContinue
# Results in this:
<#
I shouldn't see this
#> Looking into this further, I've found the following info:
Stepping back from all of this, we need to do something differently in the module, and we need to do it consistently (as Two clear approaches we can take:
That being said, there may be cases (especially in the case of pipeline input that can contain multiple objects) where we may want to allow later objects in the pipeline to continue processing even if earlier ones failed. We'd need to look at this on a case-by-case basis and then attempt to come up with a clear plan for how we handle those situations consistently. So, with all that being said, I'm open to some proposals for how folks things we should approach this. The |
The approach in #410 is perhaps inelegant but AFAICT it induces "correct" behavior for all scenarios. Is it perhaps worth applying a gross-but-functional implementation while you ponder a better solution? If not, then FWIW I vote option 2 Pipeline input consideration suggests to me the #410 approach might be warranted though if it makes the actual behavior more correct than the alternates available at this time. |
From PowerShell/PowerShell#19500 (comment)
Pairs with a long read https://jhoneill.github.io/powershell/2022/06/13/Errors.html |
Issue Details
Get-GitHubTeam -TeamName foo -ErrorAction SilentlyContinue
returns all teams when teamfoo
doesn't exist.Steps to reproduce the issue
In the below example, I want to provision
BTeam
. I first check to see if that team exists so that I can create it if not. Instead, I end up modifying the settings forATeam
.Verbose logs showing the problem
N/A
Suggested solution to the issue
Immediately exit function
Get-GitHubTeam
when-TeamName
is specified but no match is found.Add a
return
at line 193.PowerShellForGitHub/GitHubTeams.ps1
Lines 189 to 194 in 2233b86
Requested Assignment
Operating System
PowerShell Version
Module Version
The text was updated successfully, but these errors were encountered: