Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SubscriptionClient.subscriptions.get SubscriptionNotFound Error is in the wrong format #33035

Open
5 tasks
natanel-ficher-cyera opened this issue Feb 13, 2025 · 5 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Subscription

Comments

@natanel-ficher-cyera
Copy link

  • Package Name: @azure/core-rest-pipeline": "1.19.0","@azure/arm-subscriptions": "5.1.0"
  • Operating system: Mac
  • nodejs
    • version: v18.20.4
  • typescript
    • version: 4.8.4
  • Is the bug related to documentation in

Describe the bug
When you use SubscriptionClient.subscriptions.get(subscriptionId) on a subscription that does not exist, An error is thrown
the TS typing makes it seem like error.code === 'SubscriptionNotFound' and error.message = "The subscription '...' was not found."

but instead what you get is error.code === undefined and error.message = {error:"code": "SubscriptionNotFound", message: "The subscription '...' was not found."}, which goes against the Typing of message:string and means in TS you cannot check for 'SubscriptionNotFound' without TS shenanigans.

To Reproduce
Steps to reproduce the behavior:

  1. call .get on a subscription that does not exist

example:
const client = new SubscriptionClient(CREDENTIALS) client.subscriptions.get(FAKE_ID)

Expected behavior
I would expect the returned error to have error.code === 'SubscriptionNotFound' and error.message = "The subscription '...' was not found."

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Feb 13, 2025
@xirzec xirzec added Client This issue points to a problem in the data-plane of the library. Mgmt This issue is related to a management-plane library. bug This issue requires a change to an existing behavior in the product in order to be resolved. Subscription and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Feb 14, 2025
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Feb 14, 2025
@xirzec xirzec removed the Client This issue points to a problem in the data-plane of the library. label Feb 14, 2025
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Feb 14, 2025
@xirzec
Copy link
Member

xirzec commented Feb 14, 2025

@joheredi @qiaozha looks like there might been an emitter issue here

@qiaozha
Copy link
Member

qiaozha commented Feb 20, 2025

@xirzec @azure/arm-subscription is a HLC library. This problem happens on how we handled the error response

const error = new RestError(initialErrorMessage, {
in core-client. But I am not sure if we should fix it, as there maybe some other customers that are parsing the original error inside the message?

For modular and RLC, we have already fixed it in core client rest here https://github.com/Azure/azure-sdk-for-js/pull/27867/files and in codegen here Azure/autorest.typescript#1997

@xirzec
Copy link
Member

xirzec commented Feb 20, 2025

@qiaozha Maybe I'm misunderstanding something here, but isn't the problem that the spec for this API doesn't have a default response shape?

https://github.com/Azure/azure-rest-api-specs/blob/f80f83ae1cbefd1bd8d512452353795a0e4efcdc/specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/subscriptions.json#L119

Since that causes us to throw on this line:

But when the spec does have at least a default handler we set the code and message here:

Perhaps we could do something smarter here, like see if the parsedBody is a "standard" error shape, even if we don't have the original message? I do agree there is some risk of folks currently working around this by doing JSON.parse of the message though.

@jeremymeng
Copy link
Member

Perhaps we could do something smarter here, like see if the parsedBody is a "standard" error shape, even if we don't have the original message? I do agree there is some risk of folks currently working around this by doing JSON.parse of the message though.

Yes we could try some heuristic in deserializationPolicy.ts to help the experience. Let me take a look into this.

jeremymeng added a commit to jeremymeng/azure-sdk-for-js that referenced this issue Feb 21, 2025
…ult body mapper

Currently, when we receive an error response and there is no default body mapper, we immediately throw a
RestError without further inspecting the response body. It's ideal for operation specifications to define a
default mapper for unexpected responses. However, some services did not implement this leading to issues like
Azure#33035 where the error message contains a JSON string of the
error object, and the error code is undefined.

This PR modifies the behavior to look into parsedBody if it has an 'error' property that contains both
'code' and 'message' properties, improving the developer experience in this scenario.
jeremymeng added a commit to jeremymeng/azure-sdk-for-js that referenced this issue Feb 21, 2025
…ult body mapper

Currently, when we receive an error response and there is no default body mapper, we immediately throw a
RestError without further inspecting the response body. It's ideal for operation specifications to define a
default mapper for unexpected responses. However, some services did not implement this leading to issues like
Azure#33035 where the error message contains a JSON string of the
error object, and the error code is undefined.

This PR modifies the behavior to look into parsedBody if it has an 'error' property that contains both
'code' and 'message' properties, improving the developer experience in this scenario.
@qiaozha
Copy link
Member

qiaozha commented Feb 21, 2025

@xirzec I see your point, I will contact the service team to add error response here.
But I realize the logic of handling error response is slightly different between Modular and HLC. in Modular, we parse the error code for unsuccessful status including expected error and unexpected error, but in HLC, we only parse the error code for expected error status. would it be a concern when we migrate to Modular from HLC?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Subscription
Projects
None yet
Development

No branches or pull requests

5 participants