Skip to content

Show more details on errors for New-AzVirtualNetwork when there are duplicate Subnets #9920

Open
@WillyMoselhy

Description

@WillyMoselhy

Problem

When using array object for the Subnet parameter of New-AzVirtualNetwork command. If there is a duplicate subnet (same name) we get the following error:

StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 'f5cdb7f6-c616-40fd-91b3-c20d05bba58c'
At line:1 char:9
+ $VNet = New-AzVirtualNetwork -Name $VNetName -ResourceGroupName $RGNa ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [New-AzVirtualNetwork], NetworkCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.NewAzureVirtualNetworkCommand

By enabling -Debug we can see the actual issue:

  "error": {
    "code": "InvalidRequestFormat",
    "message": "Cannot parse the request.",
    "details": [
      {
        "code": "DuplicateResourceName",
        "message": "Resource /subscriptions//resourceGroups//providers/Microsoft.Network/virtualNetworks/ has two child resources with the same name (SL-App)."
      }
    ]
  }

Proposed implementation details (optional)

Allow the error message to include why the command has failed instead of juts saying 400 / Bad request

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions