azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG]ErrorResponseException's body isn't printed in ToString()
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
Label prediction was below confidence level 0.6
for Model:ServiceLabels
: 'Service Bus:0.4197042,Event Grid:0.022255523,EngSys:0.02031645'
Thank you for your feedback. Tagging and routing to the team member best able to assist.
@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
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.
as long as the namespace start with Microsoft.Azure.Management, they are deprecated
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.
@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?
It's not just one module. One simple fix can fix a lot of copy/paste fixes. Feel free to close the ticket.