Azure / Azure/azure-powershell

ManagementGroup cmdlets do not pass InnerException back to caller

Open
#15,938 2 comments 0 reactions 0 assignees View on GitHub
act-identity-squad ARM - Core feature-request Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

## Description of the new feature

All other Az Powershell cmdlets return the details of the REST API response in the error's InnerException property whenever an error is encountered. This makes it possible to do things such as:
```
try
{
Set-AzNetworkSecurityGroup ....
}
catch
{
if ($_.Exception.InnerException.Body.Code -eq "ResourceGroupNotFound")
...
elseif ($_.Exception.InnerException.Body.Code -in @("Canceled", "CanceledAndSupersededDueToAnotherOperation"))
...
}
```

But for the Management Group cmdlets such as New-AzManagementGroupSubscription, only the error message is returned to the caller so it isn't possible to query for things such as the code or details.

This is done in https://github.com/Azure/azure-powershell/blob/main/src/Resources/Resources/ManagementGroups/Common/Utility.cs with:
```
if (content.ContainsKey("Message"))
{
throw new CloudException(content["Message"].ToString());
}
```

This should be changed to return the full error details the same way other Az cmdlets do.

## Proposed implementation details (optional)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.