azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[BUG]ErrorResponseException's body isn't printed in ToString()

Open rachelxj-ms opened this issue 2 years ago • 7 comments

Library name and version

Microsoft.Azure.Management.Authorization:2.13.0

Describe the bug

https://github.com/Azure/azure-powershell/issues/19605, New-AzRoleAssignment doesn't return error other than status code. https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/authorization/Microsoft.Azure.Management.Authorization/src/Generated/Models/ErrorResponseException.cs The detailed error message is set in body, but ToString() is not overwritten in the class. It seems it's a common issue. It's better SDK can print all error messages.

Expected behavior

Expected the error details will be printed.

New-AzRoleAssignment: Operation returned an invalid status code 'Conflict'. {"code":"RoleAssignmentExists","message":"The role assignment already exists."}

In this case, Body.Error.ToJson() is {"code":"RoleAssignmentExists","message":"The role assignment already exists."}

Actual behavior

It only prints error code. New-AzRoleAssignment: Operation returned an invalid status code 'Conflict'

Reproduction Steps

Grant the permissions on an Azure subscription to a certain user, group, or service principal Run a command to grant the permissions again New-AzRoleAssignment -ObjectId $id -RoleDefinitionName $role -Scope "/subscriptions/$sub"

Environment

No response

rachelxj-ms avatar Nov 08 '22 07:11 rachelxj-ms

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'Service Bus:0.4197042,Event Grid:0.022255523,EngSys:0.02031645'

azure-sdk avatar Nov 08 '22 07:11 azure-sdk

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire avatar Nov 08 '22 15:11 jsquire

@rachelxj-ms the library you are using is our track 1 SDK and it is deprecated, please check our deprecation announcement. As a replacement, you can use this package: https://www.nuget.org/packages/Azure.ResourceManager.Authorization

xboxeer avatar Nov 09 '22 03:11 xboxeer

I searched ErrorResponseException in this repository. There are 1408 code results in Azure/azure-sdk-for-net. It's implemented in multiple library. Are those libraries deprecated? It's a common issue, not only in Microsoft.Azure.Management.Authorization.

rachelxj-ms avatar Nov 10 '22 01:11 rachelxj-ms

as long as the namespace start with Microsoft.Azure.Management, they are deprecated

xboxeer avatar Nov 10 '22 05:11 xboxeer

Please check this: https://github.com/Azure/azure-sdk-for-net/search?q=ErrorResponseException It means other libraries have the same issue. ErrorResponseException doesn't overwrite ToString() to print body as well. image

rachelxj-ms avatar Nov 10 '22 06:11 rachelxj-ms

@rachelxj-ms I checked the other issue you mentioned in azure powershell repo and indeed we have a long story with powershell team regarding the new SDK vs old SDK, since Powershell will go to provide a fix without touching SDK, are we cool to close this issue?

xboxeer avatar Nov 11 '22 08:11 xboxeer

It's not just one module. One simple fix can fix a lot of copy/paste fixes. Feel free to close the ticket.

rachelxj-ms avatar Nov 17 '22 09:11 rachelxj-ms