Skip to content

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

Closed
Peter Vandivier (petervandivier) wants to merge 1 commit into
microsoft:masterfrom
petervandivier:master
Closed

Peter Vandivier (petervandivier) wants to merge 1 commit into
microsoft:masterfrom
petervandivier:master

Conversation

@petervandivier

@petervandivier Peter Vandivier (petervandivier) commented Jun 26, 2023 •

Copy link
Copy Markdown

Description

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

Issues Fixed

References

N/A

Checklist

  • You actually ran the code that you just wrote, especially if you did just "one last quick change".
    • screencap below shows...
      1. updated commit for this change
      2. behavior without -TeamName param remains the same
      3. error behavior remains the same
      4. empty stdout on error remains
      5. -ea 0 invocation
      6. -ea 0 with non-existent team now returns empty set ✨
image
  • Comment-based help added/updated, including examples.
    • No, adding CBH would describe behavior which is expected already
  • Static analysis is reporting back clean.
  • New/changed code adheres to our coding guidelines.
  • Formatters were created for any new types being added.
    • N/A
  • New/changed code continues to support the pipeline.
    • AFAICT? 🤔
  • Unit tests were added/updated and are all passing. See testing guidelines. This includes making sure that all pipeline input variations have been covered.
    • N/A
  • Changes to the manifest file follow the manifest guidance.
    • N/A
  • Relevant usage examples have been added/updated in USAGE.md.
  • If desired, ensure your name is added to our Contributors list

@HowardWolosky

Copy link
Copy Markdown
Contributor

Thanks for the contribution Peter Vandivier (@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):

if ($null -eq $team)
{
$message = "Unable to find the team [$TeamName] within the organization [$OrganizationName]."
Write-Log -Message $message -Level Error
throw $message
}

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

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exported functions not behaving correctly with -ErrorAction SilentlyContinue

2 participants