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

Type comparison with UnderlyingExceptions might not be working as expected. #4693

Closed
2 of 14 tasks
jmartins-sh opened this issue Apr 12, 2024 · 8 comments
Closed
2 of 14 tasks
Assignees
Labels
auth Issues related to the Auth Category bug Something is not working; the issue has reproducible steps and has been reproduced pending-release Issues that have been addressed in main but have not been released

Comments

@jmartins-sh
Copy link

Description

Hello there! I'm currently testing scenarios where Cognito triggers (Lambdas) might return validation errors. While catching the LambdaException, I noticed that the underlying exception has a prefix of "_$".

For example, I encountered _$UserLambdaValidationException, whereas the exception provided by amplify-flutter is simply UserLambdaValidationException (without the "_$").

Is this expected behavior? Did I misunderstand something?

Appreciate the help. :)

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Notifications (Push)
  • Storage

Steps to Reproduce

  1. Create a lambda that throws an Error("Not authorized to use the system.");
  2. Catch the exception in flutter code
  3. Compare the type of underlying exception (supposed to be the _$UserLambdaValidationException) inside the LambdaException with UserLambdaValidationException
  4. The comparison returns false.

Screenshots

image (1)

image

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Flutter Version

3.19.1

Amplify Flutter Version

1.7.0

Deployment Method

Amplify CLI

Schema

No response

@Jordan-Nelson
Copy link
Contributor

Jordan-Nelson commented Apr 13, 2024

Hello @joaoantoniomartinsfilho

_$UserLambdaValidationException extends UserLambdaValidationException. Here is the class definition. It is an internal class used for json serialization with built_value.

If you want to check if the exception is a UserLambdaValidationException you can do the following.

if (e is UserLambdaValidationException) {
  // handle exception 
}

Let me know if you have any other questions.

@Jordan-Nelson Jordan-Nelson added question A question about the Amplify Flutter libraries auth Issues related to the Auth Category labels Apr 13, 2024
@Jordan-Nelson Jordan-Nelson self-assigned this Apr 13, 2024
@jmartins-sh
Copy link
Author

jmartins-sh commented Apr 13, 2024

Hey @Jordan-Nelson, how's it going?

Thanks for the reply.

Do you mean checking directly the underlying exception, instead of the runtime type?

@jmartins-sh
Copy link
Author

Hey @Jordan-Nelson , I followed your suggestion, but even after that, the comparison using the is operator with underlyingException is returning false, as you can check in the screenshot below.

Did I misunderstand something, or is there something else I need to consider?

image

@Jordan-Nelson
Copy link
Contributor

@joaoantoniomartinsfilho You are not missing anything. That looks like unexpected behavior. We will see if we can reproduce it.

@Jordan-Nelson Jordan-Nelson added Investigating Issues that are assigned and are being looked into and removed question A question about the Amplify Flutter libraries labels Apr 13, 2024
@Jordan-Nelson
Copy link
Contributor

Hello @joaoantoniomartinsfilho - This does appear to be a bug. The exception is not getting mapped correctly. e should be type UserLambdaValidationException, not LambdaException.

The reason that you are not able to type check the underlying exception is that there are actually two UserLambdaValidationException types. One is public and extends AmplifyException. The other is private and is only intended to be used internally. The underlying exception is the private/internal one. However, if e was the correct type you would not need to check the type of e.underlyingException

Thanks for raising the issue. I will look into a fix and let you know when we have an update.

@Jordan-Nelson Jordan-Nelson added bug Something is not working; the issue has reproducible steps and has been reproduced and removed Investigating Issues that are assigned and are being looked into labels Apr 30, 2024
@Jordan-Nelson Jordan-Nelson added the pending-release Issues that have been addressed in main but have not been released label May 6, 2024
@Jordan-Nelson
Copy link
Contributor

@jmartins-sh - This issue was addressed in Amplify Flutter v2 which was released a couple weeks ago. There were some breaking changes in this version. Please see the upgrade guide for more info.

@jmartins-sh
Copy link
Author

jmartins-sh commented May 22, 2024

Hey @Jordan-Nelson, thanks for the reply.

I just have one more question, is the lib amplify-flutter independent of Amplify Gen 2 right? Or Am I getting this wrong? My project is currently running in Amplify Gen 1 (amplify-cli and cloud). Will we face any issues using the lib 2.0?

Appreciate it.

@Jordan-Nelson
Copy link
Contributor

Hi @jmartins-sh - Amplify Flutter v2 is compatible with Amplify Gen 1 and Amplify Gen 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth Issues related to the Auth Category bug Something is not working; the issue has reproducible steps and has been reproduced pending-release Issues that have been addressed in main but have not been released
Projects
None yet
Development

No branches or pull requests

2 participants