microsoft / PowerShellForGitHub

Microsoft PowerShell wrapper for GitHub API
Other
588 stars 186 forks source link

`Get-GitHubTeam -TeamName NonExistentTeam -ErrorAction SilentlyContinue` returns empty set #410

Closed petervandivier closed 1 year ago

petervandivier commented 1 year ago

Description

Get-GitHubTeam -TeamName NonExistentTeam -ErrorAction SilentlyContinue returns empty set instead of teams you didn't name

Issues Fixed

References

N/A

Checklist

image
HowardWolosky commented 1 year ago

Thanks for the contribution @petervandivier. throw should be a terminating error, and ErrorActionPreference is supposed to only allow you to alter the behavior of non-terminating errors. I wouldn't expect you to be able to bypass the throw with SilentlyContinue, and yet I was able to repro exactly that.

-ErrorAction documentation (ephasis mine):

Determines how the cmdlet responds to a non-terminating error from the command. This parameter works only when the command generates a non-terminating error, such as those from the Write-Error cmdlet. ... The ErrorAction parameter has no effect on terminating errors (such as missing data, parameters that aren't valid, or insufficient permissions) that prevent a command from completing successfully.

There are a number of places where this could additionally have issues (like for example in the very next method: Get-GitHubTeamMember):

https://github.com/microsoft/PowerShellForGitHub/blob/2233b86601bae63413e55a51932d3449cfca90df/GitHubTeams.ps1#L295-L300

I don't want to fix these all one-off. I'd like to address all of these in a single changelist so that we can ensure that we're approaching that issue in a consistent manner across the entire module. And I wouldn't want to do that until I had a better understanding of why -ErrorAction SilentlyContinue is altering the behavior of a terminating error.

If you have more context as to why PowerShell is allowing -ErrorAction SilentlyContinue to bypass a terminating throw command, please add it to the issue that you opened so that we can come up with a holistic approach to fixing this issue across the entire project.

HowardWolosky commented 1 year ago

I've updated the original issue with more details on the problem and suggested approaches that can be taken to move forward.