azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Automation RM cmdlets don't adhere to erroractionpreference

Open trondhindenes opened this issue 11 years ago • 29 comments

Repro: Get-AzureRmAutomationRunbook -Name "DoesNotExist" -ErrorAction SilentlyContinue

Result: Throws error Expected result: supresses error

I thought we were passed these bugs...

trondhindenes avatar Oct 20 '15 08:10 trondhindenes

@jodoglevy can we get this fixed up prior to 1.0 release.

devigned avatar Oct 23 '15 21:10 devigned

@trondhindenes this is specific to automation cmdlets? I don't think we're doing anything specific with error action

JAL9302 avatar Oct 23 '15 21:10 JAL9302

Hard to say - The automation cmdlets are the only ones I've been using. But you're definetely doing erroraction wrong in the current ver (and not just in the cmdlet I used in my example).

trondhindenes avatar Oct 23 '15 22:10 trondhindenes

I just tried with Get-AzureRmVM, Same issue. This is not specific to Automation cmdlets. It's a problem with all of Azure PS 1.0 preview.

JAL9302 avatar Oct 23 '15 22:10 JAL9302

@singhkay looks like this is happening in VM cmdlets too.

devigned avatar Oct 23 '15 22:10 devigned

@hyonholee Can you check the VM cmdlets in the preview module?

singhkays avatar Oct 23 '15 23:10 singhkays

@singhkay @hyonholee @trondhindenes @jodoglevy This may be expected. Terminating errors should result in failures regardless of ErrorActionPreference. Only non-terminating ewrrors should be controlled this way, see https://msdn.microsoft.com/en-us/library/ms714414(v=vs.85).aspx

markcowl avatar Oct 30 '15 23:10 markcowl

Yup, tgat makes sense. Tho I don't understand the rationale for throwing terminating errors.

trondhindenes avatar Oct 30 '15 23:10 trondhindenes

It appears these are exceptions, although I don't think they should be:

try { Get-AzureRMVm -ResourceGroupName "dsfd" -Name "fdsfds" } catch { "EXCEPTION!!" }

results in "EXCEPTION!!" but

try { Get-AzureVM -Name "sdds" -servicename "fdssfd" } catch { "EXCEPTION!!" }

does not.

Same with automation cmdlets:

try { Get-AzureRmAutomationRunbook -ResourceGroupName "dfds" -AutomationAccountName "ddd" -Name "sdsd" } catch { "EXCEPTION!!" }

results in "EXCEPTION!!" but

try { Get-AzureAutomationRunbook -AutomationAccountName "ddd" -Name "sdd" } catch { "EXCEPTION!!" }

does not

@safeermohammed any ideas?

JAL9302 avatar Oct 31 '15 00:10 JAL9302

Terminating/Non-terminating errors need to be absolutely predictable - otherwise it is impossible to effectively build solutions using the module - especially headless scripts where we need to be super-picky about error-handling. Please get this fixed.

trondhindenes avatar Nov 03 '15 12:11 trondhindenes

@safeermohammed did we change anything with regards to error handling from our ASM to our ARM cmdlets?

JAL9302 avatar Nov 04 '15 00:11 JAL9302

@jodoglevy . None I am aware of. @markcowl Can you please take a look at this?

safeermohammed avatar Nov 04 '15 00:11 safeermohammed

There's definetively differences. For example (all against non-existing things): get-azurevm -Name "smokk" -ServiceName "kvekk": returns warning, but no error Get-AzureRmVM -ResourceGroupName "kokk" -Name "krokk": throws a TERMINATING error.

Start-AzureAutomationRunbook -Name "jker" -AutomationAccountName "jojojo": non-terminating Start-AzureRmAutomationRunbook -Name "kjkj" -ResourceGroupName "jojojo" -AutomationAccountName "jjjjj": throws a TERMINATING error.

The fact that the rm cmdlets throw TERMINATING errors is (excuse my french) bollocks. Please read up on the PowerShell design guidelines:

"For a non-terminating error that does not stop operation on the next record that is coming from the pipeline (for example, a record produced by a different process), the cmdlet must call the WriteError method"

given a pipe or array of objects, for example a single not-found vm does not stop PowerShell from processing the next record, and therefore a terminating error should never be thrown. Terminating errors should (IMHO) only be used in cases where the cmdlet loses connection to the underlying rest api or similar. Look at how most (Microsoft-supplied) modules are written, and you will see that they VERY rarely throw terminating errors during "regular operations". Please get this sorted, it is a major bug.

trondhindenes avatar Nov 05 '15 10:11 trondhindenes

@mayurid and @markcowl this sounds like there was a change in behavior. If so, we need to fix this.

devigned avatar Nov 05 '15 17:11 devigned

Looking at some of the modules, I can't see any unit tests covering error schenarios, so no wonder this wasn't picked up. I would advise you to add integration tests covering failure scenarios to make sure cmdlets output the right error type.

trondhindenes avatar Nov 06 '15 10:11 trondhindenes

@trondhindenes @devigned I think we have let the perfect be the enemy of the good in this case. It is technically true that the decision whether an error is terminating or non-terminating should be made on a case-by-case basis, but most errors that occur in ProcessRecord will be non-terminating. We will update the cmdlet advice to designate terminating errors using ThrowTerminatingError and catch other execptions thrown during ProcessRecord and use WriteError() to make them non-terminating

markcowl avatar Nov 11 '15 00:11 markcowl

Awesome, thanks for looking at this @markcowl.

JAL9302 avatar Nov 11 '15 02:11 JAL9302

Thanks @markcowl looking forward to this!

trondhindenes avatar Nov 11 '15 09:11 trondhindenes

Can't wait to see this fixed as it cause a lot of problems porting our existing scripts.

Our migration to v1.x have been completely stopped until this is fixed, it is a show stopper for us.

slapointe avatar Nov 19 '15 20:11 slapointe

Still no resolution on this ? This has broken pretty much every script in out deployment pipeline. I don't see how calling Get-AzureRmWebApp on a web app that doesn't exist should be considered a terminating error.

graemechristie avatar Dec 11 '15 07:12 graemechristie