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

@aws-sdk/client-lightsail throws the base exception instead of a specific exception #6606

Closed
3 tasks done
omid-sadeghi opened this issue Nov 30, 2023 · 7 comments
Closed
3 tasks done
Assignees
Labels
p2 This is a standard priority issue service-api This issue is due to a problem in a service API, not the SDK implementation. wontfix We have determined that we will not resolve the issue.

Comments

@omid-sadeghi
Copy link

Checkboxes for prior research

Describe the bug

In lightsail-client, when GetStaticIpCommand and GetInstanceCommand don't find the resource, they throw LightsailServiceException but according to the docs for GetStaticIpCommand and GetInstanceCommand, they should throw NotFoundException and the current behaviour makes instanceof useless for checking type of the exception at runtime because LightsailServiceException is the base exception. Unfortunately, I must resort to checking by the the name property.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.9.0

Reproduction Steps

import { LightsailClient,  GetInstanceCommand,  GetStaticIpCommand, NotFoundException, LightsailServiceException} from "@aws-sdk/client-lightsail";
    
const client = new LightsailClient({});

try{
    await client.send(new GetInstanceCommand({instanceName: "non-existent instance"}));
}
catch(e){
    if(e instanceof NotFoundException)
        console.log("NotFoundException")
    else if(e instanceof LightsailServiceException)
        console.log("LightsailServiceException");
}

try{
    await client.send(new GetStaticIpCommand({staticIpName: "non-existent static ip"}));
}
catch(e){
    if(e instanceof NotFoundException)
        console.log("NotFoundException")
    else if(e instanceof LightsailServiceException)
        console.log("LightsailServiceException");
}

Observed Behavior

The code outputs:
LightsailServiceException
LightsailServiceException

Expected Behavior

I expect to see:
NotFoundException
NotFoundException

Possible Solution

No response

Additional Information/Context

No response

@omid-sadeghi omid-sadeghi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 30, 2023
@omid-sadeghi omid-sadeghi changed the title @aws-sdk/client-lightsail throws base exception instead of specific exception @aws-sdk/client-lightsail throws the base exception instead of a specific exception Nov 30, 2023
@RanVaknin
Copy link
Contributor

Hi @omid-sadeghi ,

Thanks for reaching out. The error you are seeing is a modeled error coming from the service. The SDK team cannot change this service side behavior.

and the current behaviour makes instanceof useless for checking type of the exception at runtime because LightsailServiceException is the base exception. Unfortunately, I must resort to checking by the the name property.

I'm not sure I understand how LightsailServiceException being the base exception prevents you from using instanceof as it is also a modeled exception.

Additionally, after probing the API and logging the actual error message alongside with the error code, I can see the Lightsail uses LightsailServiceException as kind of a catch-all exception, but they make up for it by providing very explicit error messages. So for example using your input "non-existent instance" we are going to run into a service side validation error:

LightsailServiceException InvalidResourceName: non-existent%20instance is not a valid resource name. Resource names must be at least 2 characters long and contain only alphanumerics, -, _, and .

Changing the resource name to fit the validation rules to soemthing like: "nonExistentInstance_123", will result in the same exception but a different error message:

LightsailServiceException DoesNotExist: The Instance does not exist: nonExistentInstance_123

Lastly, while this does seem like a documentation discrepancy where the service documents one thing, but returns another, it's possible that we are overlooking some combination of inputs where that exception is actually thrown. Unfortunately I do not have access to the server code to check for the error handling logic to give you a conclusive answer.

If there is anything else I can do to help, pleaes let me know.
All the best,
Ran~

@RanVaknin RanVaknin self-assigned this Dec 1, 2023
@RanVaknin RanVaknin added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. service-api This issue is due to a problem in a service API, not the SDK implementation. and removed needs-triage This issue or PR still needs to be triaged. labels Dec 1, 2023
Copy link

github-actions bot commented Dec 9, 2023

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Dec 9, 2023
@omid-sadeghi
Copy link
Author

Hi @RanVaknin

So you say the issue is related to the service and you cannot do anything. Where can I possibly report the issue to so they can consider this?

You said:

I'm not sure I understand how LightsailServiceException being the base exception prevents you from using instanceof

I specifically point to a blog post in aws which says instead of using the name property of an exception, you can use instanceof to know the type of exception at runtime.

Because every exception is LightsailServiceException so instanceof cannot help in determing the type of error at runtime.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. labels Dec 10, 2023
@RanVaknin
Copy link
Contributor

Hi @omid-sadeghi ,

So you say the issue is related to the service and you cannot do anything. Where can I possibly report the issue to so they can consider this?

You can use the AWS console to open a support ticket and ask for it to be routed to the Lightsail service team.

Because every exception is LightsailServiceException so instanceof cannot help in determing the type of error at runtime.

Ah yes, I agree with this sentiment, the error returned is not very useful, but you can still use instanceof on LightsailServiceException.

I'm going to transfer this to the cross SDK repository since this is not an SDK specific problem. Feel free to mention my internal AWS alias rvaknin when you open the ticket, I'll be able to give the Lightsail team some more info if necessary.

Thank you for the clarification. Keep us posted.
Ran~

@RanVaknin RanVaknin transferred this issue from aws/aws-sdk-js-v3 Dec 14, 2023
@omid-sadeghi
Copy link
Author

omid-sadeghi commented Dec 26, 2023

Thank you @RanVaknin

Unfortunately In my AWS console I have Basic Support plan which excludes technical support and I cannot open a ticket for this case.

By the way, I used workarounds to do my job but if this exception thing is corrected, we can write a better code. I hope this problem is solved.

@zshzbh zshzbh transferred this issue from aws/aws-sdk Oct 30, 2024
@zshzbh zshzbh added the p2 This is a standard priority issue label Nov 14, 2024
@zshzbh
Copy link
Contributor

zshzbh commented Jan 8, 2025

Hey there,

Just got back from service team -

Please refer https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetInstance.html#API_GetInstance_Errors

The service team indicates that you need to be checking for InvalidInputException in addition to NotFoundException. Since the provided input name is invalid, the request is failing with that type of error rather than the type not-found.

Also LightsailServiceException is NOT the same as ServiceException - the latter is one of types of LightsailServiceException where the former i.e. <any_AWS_service_name>+ServiceException is a naming concept AWS-SDK has created to wrap all exceptions returned by any AWS service.

I will try to execute and repro later to confirm, but the below should be code fix they need to make ->

import { LightsailClient,  GetInstanceCommand,  GetStaticIpCommand, NotFoundException, InvalidInputException, LightsailServiceException} from "@aws-sdk/client-lightsail";
    
const client = new LightsailClient({});

try{
    await client.send(new GetInstanceCommand({instanceName: "non-existent instance"}));
}
catch(e){
    if(e instanceof NotFoundException)
        console.log("NotFoundException")
   else if(e instanceof InvalidInputException) //FIX NEEDED IN REPORTER's CODE
        console.log("InvalidInputException")
    else if(e instanceof LightsailServiceException)
        console.log("LightsailServiceException");
}

There is no service issue neither in code nor documentation.

Closing this ticket.

Thanks!
Maggie

@zshzbh zshzbh added guidance General information and guidance, answers to FAQs, or recommended best practices/resources. and removed bug This issue is a bug. labels Jan 8, 2025
@zshzbh zshzbh closed this as completed Jan 8, 2025
@zshzbh zshzbh added wontfix We have determined that we will not resolve the issue. and removed guidance General information and guidance, answers to FAQs, or recommended best practices/resources. labels Jan 8, 2025
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2 This is a standard priority issue service-api This issue is due to a problem in a service API, not the SDK implementation. wontfix We have determined that we will not resolve the issue.
Projects
None yet
Development

No branches or pull requests

3 participants