-
Notifications
You must be signed in to change notification settings - Fork 256
App crashes in production – NSInvalidArgumentException (NaN in JSON write) #5891
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
Comments
Hello @giulitu95, thanks for taking the time to open this issue. Could you please provide a sample schema and code snippet to help us reproduce this issue. |
I have identified the cause of the crash. One of my models includes a Float attribute, which is translated into a double in the generated Flutter model. The crash occurs when attempting to save a double.nan value to the DataStore. Here are the exact steps that lead to the crash: In Flutter, I call Amplify.DataStore.save(myModel), where myModel includes a parameter set to double.nan. During the .save call, the model is serialized to JSON. At this point, the JSON becomes invalid because it contains a key-value pair like:
This invalid JSON is then passed through the method channel to the native iOS plugin. Specifically, the Swift onSave method is triggered, which attempts to deserialize the JSON string using the following code: amplify-flutter/packages/amplify_datastore/ios/Classes/SwiftAmplifyDataStorePlugin.swift Lines 168 to 170 in cc36ecc
The app crashes at this point because the getJSONValue(...) function cannot handle the nan value during deserialization. The |
Hello @giulitu95, thank you for the update. Since gmpassos has provided a fix for the statistics package and Amplify DataStore is providing the expected error message, I will close this issue unless you have any additional questions. |
Thank you @tyllark for your answer, I don't think that the crash or the freeze are expected behaviors of this library. |
Hello @giulitu95, you are correct. I will keep this issue open as a bug to create validate our models via an assert or exception if an unsupported values such as This validation will need to be included in our model generation, so we will need to coordinate with the Amplify CLI team to implement this fix. |
Description
In iOS the app often crashes when I try to save something in the Amplify DataStore. I couldn't find a reliable pattern to reproduce the issue, but I see the following error logged in Sentry:
I could not reproduce this problem in debug mode—it seems only happen in release builds and makes my app unusable. Howerver I'm sure that it has to do with the amplify library because if I remove it from the app, no crashes appear.
In the following the crashlog (crashlog.txt):
Categories
Steps to Reproduce
I cannot find a pattern that reproduce this problem but it appears whenever the app saves elements in the datastore with a high frequency
Screenshots
No response
Platforms
Flutter Version
3.27.2
Amplify Flutter Version
2.6.0
Deployment Method
Amplify CLI (Gen 1)
Schema
The text was updated successfully, but these errors were encountered: