Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.23k stars 3.83k forks source link

New-AzSqlElasticPool throws aggregate exception #9560

Closed adeal closed 5 years ago

adeal commented 5 years ago

Description

This cmdlet does not have a good error experience. It seems to always throw an aggregate exception even in the presence of a single error. This requires users to dig into the $error object to determine the real failure reason.

Steps to reproduce

New-AzSqlElasticPool -ElasticPoolName hs -Edition Hyperscale -ServerName adeal-stage-neu -ResourceGroupName work
New-AzSqlElasticPool : One or more errors occurred.
At line:1 char:1
+ New-AzSqlElasticPool -ElasticPoolName hs -Edition Hyperscale -ServerN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzSqlElasticPool], AggregateException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet.NewAzureSqlElasticPool

PS C:\WINDOWS\system32> $error[2].Exception.InnerExceptions
'Hyperscale' is not a valid database edition in this version of SQL Server.

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.17763.503
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.503
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module versions

Script     1.12.0     Az.Sql                              {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseTransparentDataEncryptionActivity, Set-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlDatabaseUpgradeHint...}

Debug output

PS C:\WINDOWS\system32> New-AzSqlElasticPool -ElasticPoolName hs -Edition Hyperscale -ServerName adeal-stage-neu -ResourceGroupName work
DEBUG: 1:33:42 PM - NewAzureSqlElasticPool begin processing with ParameterSet 'DtuBasedPool'.
DEBUG: 1:33:42 PM - using account id 'adeal@microsoft.com'...
DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '07/04/2019 21:15:51 +00:00', MultipleResource? 'True', Tenant: 'f686d426-8d16-42db-81b7-ab578e110ccd', UserId: 'adeal@microsoft.com'
DEBUG: [Common.Authentication]: User info for token DisplayId: 'adeal@microsoft.com', Name: Austin Deal, IdProvider: 'https://sts.windows-ppe.net/f686d426-8d16-42db-81b7-ab578e110ccd/', Uid: 'af650610-0f65-4727-9eab-0ae12eb17005'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '07/04/2019 21:15:51 +00:00' Comparing to '07/04/2019 20:33:42 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:42:09.1396938'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://api-dogfood.resources.windows-int.net/subscriptions/1e23e9a4-d8a0-4fdf-8261-eb8f786ffcbc/resourceGroups/work/providers/Microsoft.Sql/servers/adeal-stage-neu/elasticPools/hs?api-version=2017-10-01-preview

Headers:
x-ms-client-request-id        : 281fada3-0479-401f-aca5-ff6b4d94e81e
accept-language               : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotFound

Headers:
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-request-id               : 4343886d-da44-42fc-8e42-e5f9beca23d4
x-ms-correlation-request-id   : 4343886d-da44-42fc-8e42-e5f9beca23d4
x-ms-routing-request-id       : NORTHEUROPE:20190704T203342Z:4343886d-da44-42fc-8e42-e5f9beca23d4
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Thu, 04 Jul 2019 20:33:42 GMT

Body:
{
  "error": {
    "code": "ResourceNotFound",
    "message": "The Resource 'Microsoft.Sql/servers/adeal-stage-neu/elasticpools/hs' under resource group 'work' was not found."
  }
}

DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '07/04/2019 21:15:51 +00:00', MultipleResource? 'True', Tenant: 'f686d426-8d16-42db-81b7-ab578e110ccd', UserId: 'adeal@microsoft.com'
DEBUG: [Common.Authentication]: User info for token DisplayId: 'adeal@microsoft.com', Name: Austin Deal, IdProvider: 'https://sts.windows-ppe.net/f686d426-8d16-42db-81b7-ab578e110ccd/', Uid: 'af650610-0f65-4727-9eab-0ae12eb17005'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '07/04/2019 21:15:51 +00:00' Comparing to '07/04/2019 20:33:42 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:42:08.3601219'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://api-dogfood.resources.windows-int.net/subscriptions/1e23e9a4-d8a0-4fdf-8261-eb8f786ffcbc/resourceGroups/work/providers/Microsoft.Sql/servers/adeal-stage-neu?api-version=2015-05-01-preview

Headers:
x-ms-client-request-id        : 4207491e-9e3b-4efc-aaa2-aff4ce0adda0
accept-language               : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
x-ms-request-id               : d1fde54f-6b53-4c26-8a44-8da11a81c180
x-ms-ratelimit-remaining-subscription-reads: 14981
x-ms-correlation-request-id   : a8549de6-1e03-4110-85bd-6876e67642e0
x-ms-routing-request-id       : NORTHEUROPE:20190704T203343Z:a8549de6-1e03-4110-85bd-6876e67642e0
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Thu, 04 Jul 2019 20:33:43 GMT
Server                        : Microsoft-HTTPAPI/2.0

Body:
{
  "kind": "v12.0",
  "properties": {
    "administratorLogin": "adeal",
    "version": "12.0",
    "state": "Ready",
    "fullyQualifiedDomainName": "adeal-stage-neu.sqltest-eg1.mscds.com"
  },
  "location": "northeurope",
  "id": "/subscriptions/1e23e9a4-d8a0-4fdf-8261-eb8f786ffcbc/resourceGroups/work/providers/Microsoft.Sql/servers/adeal-stage-neu",
  "name": "adeal-stage-neu",
  "type": "Microsoft.Sql/servers"
}

DEBUG: [Common.Authentication]: Renewing Token with Type: 'Bearer', Expiry: '07/04/2019 21:15:51 +00:00', MultipleResource? 'True', Tenant: 'f686d426-8d16-42db-81b7-ab578e110ccd', UserId: 'adeal@microsoft.com'
DEBUG: [Common.Authentication]: User info for token DisplayId: 'adeal@microsoft.com', Name: Austin Deal, IdProvider: 'https://sts.windows-ppe.net/f686d426-8d16-42db-81b7-ab578e110ccd/', Uid: 'af650610-0f65-4727-9eab-0ae12eb17005'
DEBUG: [Common.Authentication]: Checking token expiration, token expires '07/04/2019 21:15:51 +00:00' Comparing to '07/04/2019 20:33:43 +00:00' With threshold '00:05:00', calculated time until token expiry: '00:42:07.7424690'
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PUT

Absolute Uri:
https://api-dogfood.resources.windows-int.net/subscriptions/1e23e9a4-d8a0-4fdf-8261-eb8f786ffcbc/resourceGroups/work/providers/Microsoft.Sql/servers/adeal-stage-neu/elasticPools/hs?api-version=2017-10-01-preview

Headers:
x-ms-client-request-id        : fdf31bcb-93a4-4c97-a398-b0ad820a6fdd
accept-language               : en-US

Body:
{
  "sku": {
    "name": "HS",
    "tier": "Hyperscale"
  },
  "properties": {
    "perDatabaseSettings": {}
  },
  "location": "northeurope"
}

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
x-ms-request-id               : 7114a77f-414a-4261-924f-3161d46e4373
x-ms-ratelimit-remaining-subscription-writes: 1195
x-ms-correlation-request-id   : 73ab74f7-ca50-4e21-8d1f-bb5887a3dc2e
x-ms-routing-request-id       : NORTHEUROPE:20190704T203344Z:73ab74f7-ca50-4e21-8d1f-bb5887a3dc2e
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Thu, 04 Jul 2019 20:33:43 GMT
Server                        : Microsoft-HTTPAPI/2.0

Body:
{
  "error": {
    "code": "InvalidTier",
    "message": "'Hyperscale' is not a valid database edition in this version of SQL Server."
  }
}

New-AzSqlElasticPool : One or more errors occurred.
At line:1 char:1
+ New-AzSqlElasticPool -ElasticPoolName hs -Edition Hyperscale -ServerN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzSqlElasticPool], AggregateException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet.NewAzureSqlElasticPool

DEBUG: AzureQoSEvent: CommandName - New-AzSqlElasticPool; IsSuccess - False; Duration - 00:00:02.3430237; Exception - System.AggregateException: One or more errors occurred. ---> Microsoft.Rest.Azure.CloudException: 'Hyperscale' is not a valid database edition in this
version of SQL Server.
   at Microsoft.Azure.Management.Sql.ElasticPoolsOperations.<BeginCreateOrUpdateWithHttpMessagesAsync>d__12.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Microsoft.Azure.Commands.Sql.ElasticPool.Services.AzureSqlElasticPoolCommunicator.Create(String resourceGroupName, String serverName, String elasticPoolName, ElasticPool parameters)
   at Microsoft.Azure.Commands.Sql.ElasticPool.Services.AzureSqlElasticPoolAdapter.CreateElasticPool(AzureSqlElasticPoolModel model)
   at Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet.NewAzureSqlElasticPool.PersistChanges(IEnumerable`1 entity)
   at Microsoft.Azure.Commands.Sql.Common.AzureSqlCmdletBase`2.<>c__DisplayClass16_0.<ExecuteCmdlet>b__0()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ConfirmAction(String processMessage, String target, Action action)
   at Microsoft.Azure.Commands.Sql.Common.AzureSqlCmdletBase`2.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
---> (Inner Exception #0) Microsoft.Rest.Azure.CloudException: 'Hyperscale' is not a valid database edition in this version of SQL Server.
   at Microsoft.Azure.Management.Sql.ElasticPoolsOperations.<BeginCreateOrUpdateWithHttpMessagesAsync>d__12.MoveNext()<---
;
DEBUG: Finish sending metric.
DEBUG: 1:33:44 PM - NewAzureSqlElasticPool end processing.
DEBUG: 1:33:44 PM - NewAzureSqlElasticPool end processing.

Error output

PS C:\WINDOWS\system32> Resolve-AzError
DEBUG: 1:34:15 PM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 1:34:15 PM - using account id 'adeal@microsoft.com'...

   HistoryId: 41

RequestId      : 7114a77f-414a-4261-924f-3161d46e4373
Message        : 'Hyperscale' is not a valid database edition in this version of SQL Server.
ServerMessage  : InvalidTier: 'Hyperscale' is not a valid database edition in this version of SQL Server. (System.Collections.Generic.List`1[Microsoft.Rest.Azure.CloudError])
ServerResponse : {BadRequest}
RequestMessage : {PUT https://api-dogfood.resources.windows-int.net/subscriptions/1e23e9a4-d8a0-4fdf-8261-eb8f786ffcbc/resourceGroups/work/providers/Microsoft.Sql/servers/adeal-stage-neu/elasticPools/hs?api-version=2017-10-01-preview}
InvocationInfo : {New-AzSqlElasticPool}
Line           : New-AzSqlElasticPool -ElasticPoolName hs -Edition Hyperscale -ServerName adeal-stage-neu -ResourceGroupName work
Position       : At line:1 char:1
                 + New-AzSqlElasticPool -ElasticPoolName hs -Edition Hyperscale -ServerN ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace     :    at Microsoft.Azure.Management.Sql.ElasticPoolsOperations.<BeginCreateOrUpdateWithHttpMessagesAsync>d__12.MoveNext()
HistoryId      : 41
markcowl commented 5 years ago

@dealaus The top level server message should be visible in the thrown error.

Note that Resolve-AzError is meant to provide additional information on errors (and does provide the server massage), but should not be required to get this minimal level of information

markcowl commented 5 years ago

Closing as this is planned for general resolution in the upcoming Az 4 preview, and there is a mitigation for current cmdlets