Open jeffpatton1971 opened 6 months ago
My current workaround is to test for the error in the catch block which for me is less than ideal, as now I have two places where I set the repo where before it was essentially one.
if (($_.Exception.Response.StatusCode.value__ -eq '422') -and ($_.ErrorDetails.Message |Select-String 'name already exists on this account') )
If this evals to true then i run get-githubrepository and capture the information I'm looking for. Again, I would prefer that when I pass -ErrorAction into the cmdlet it honors that.
I write my code inside try/catch blocks and set ErrorActionPrefernce = "Stop" and clear the error stack. When I know something will fail and I want to handle it outside the try/catch then I will pass -ErrorAction SilentlyContinue and capture the result. In the situation described in the title, I have a pipeline in Azure Devops that I use to create a repo, but I need to test if it exists first, then create it if it doesn't. I do this because New-GithubRepository fails when you attempt to create a repo. Part of the pipeline passes the reposoity object onto the pipeline so tasks further down the flow can work properly.
I know at one point this worked as my code (similar to below) is well over a year old. I can confirm the issue exists in v16 and the current v17.
Issue Details
When passing -ErrorAction SilentlyContinue into cmdlet, it should be honored and not throw an error.
Steps to reproduce the issue
Verbose logs showing the problem
Suggested solution to the issue
I'm unsure how to resolve this issue
Requested Assignment
Operating System
PowerShell Version
Module Version