Automation RM cmdlets don't adhere to erroractionpreference
Repro:
Get-AzureRmAutomationRunbook -Name "DoesNotExist" -ErrorAction SilentlyContinue
Result: Throws error Expected result: supresses error
I thought we were passed these bugs...
@jodoglevy can we get this fixed up prior to 1.0 release.
@trondhindenes this is specific to automation cmdlets? I don't think we're doing anything specific with error action
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).
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.
@singhkay looks like this is happening in VM cmdlets too.
@hyonholee Can you check the VM cmdlets in the preview module?
@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
Yup, tgat makes sense. Tho I don't understand the rationale for throwing terminating errors.
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?
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.
@safeermohammed did we change anything with regards to error handling from our ASM to our ARM cmdlets?
@jodoglevy . None I am aware of. @markcowl Can you please take a look at this?
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.
@mayurid and @markcowl this sounds like there was a change in behavior. If so, we need to fix this.
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 @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
Awesome, thanks for looking at this @markcowl.
Thanks @markcowl looking forward to this!
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.
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.