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

Passing integer to Alert causes the program to crash #36085

Closed
eirikhanasand opened this issue Feb 7, 2023 · 15 comments
Closed

Passing integer to Alert causes the program to crash #36085

eirikhanasand opened this issue Feb 7, 2023 · 15 comments
Labels
API: Alert Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@eirikhanasand
Copy link

Description

When passing an integer to Alert.alert the app will stop executing the function its in, and just move on. I think it should be possible to provide integers to alerts, or at least have an error message letting you know that the issue is that you provided the wrong data type. Would also be nice if it automatically typecasted integers/floats to strings in this scenario as its only used to display it on the screen, not to do anything with the data itself.

Example: Alert.alert("This alert will cause things to crash", 5);

Version

0.70.5

Output of npx react-native info

info Fetching system and libraries information...
System:
OS: macOS 13.0.1
CPU: (10) arm64 Apple M1 Max
Memory: 15.01 GB / 64.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 19.3.0 - ~/Desktop/Login/node_modules/.bin/node
Yarn: Not Found
npm: 8.19.2 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 17.0.6 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.5 => 0.70.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
info React Native v0.71.2 is now available (your project is running on v0.70.5).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.71.2
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.70.5
info For more info, check out "https://reactnative.dev/docs/upgrading".

Steps to reproduce

Create an alert including a number.

Example: Alert.alert("This alert will cause things to crash", 5);

Snack, code example, screenshot, or link to a repository

Full on snack wont be necessary. Reproduction is done just by making an alert containing any other type than a string.

Examples of alerts that will crash:
Alert.alert("This alert will cause things to crash", 5);
Alert.alert(2.5);

@bigcupcoffee
Copy link
Contributor

I can confirm this issue is present since at least 0.61 up until 0.71.2.
Might make a good first issue, I would take if I knew what way this desired to resolve with (my assumption is invariant/throw from JS?)

@cipolleschi
Copy link
Contributor

Hi there! I don't think that this is an issue but something designed like this. If we look at the official doc the message parameter is of optional String type, thus the platform code expect that type to work.

We can definitely change the current API to support numbers, but I think that it would be better if you can convert the number to an explicative error message, especially for the user experience.

What do you think?

@eirikhanasand
Copy link
Author

eirikhanasand commented Feb 10, 2023 via email

@cipolleschi
Copy link
Contributor

The issue here is that there is no feedback letting the user know whats going on.

In this case, you mean that there is no feedback for the developer using the Alert.alert API?

@eirikhanasand
Copy link
Author

The issue here is that there is no feedback letting the user know whats going on.

In this case, you mean that there is no feedback for the developer using the Alert.alert API?

Yes. There should be some feedback in the case that the data type is incorrect instead of just a crash.

@eirikhanasand
Copy link
Author

The issue here is that there is no feedback letting the user know whats going on.

In this case, you mean that there is no feedback for the developer using the Alert.alert API?

Yes. There should be some feedback in the case that the data type is incorrect instead of just a crash.

Because its very hard to bebug currently in a large application, and not the first thing that would come to mind

@bigcupcoffee
Copy link
Contributor

It does give some developer feedback although it's not as clear. I am currently getting Value for message/title cannot be cast from Double to String.

@cipolleschi does it make sense to just typeof and throw TypeError?

@eirikhanasand
Copy link
Author

eirikhanasand commented Feb 10, 2023 via email

@bigcupcoffee
Copy link
Contributor

Yep, but that's expo's caveat mentioned here.

I can put a PR to fix it by type-checking on JS and see if gets merged, but you'd have to wait for expo sdk update anyway.

@eirikhanasand
Copy link
Author

eirikhanasand commented Feb 10, 2023 via email

@cipolleschi
Copy link
Contributor

Starting from React Native 71, we support TypeScript as default and out-of-the-box, so the code can be type checked! :D

@bigcupcoffee
Copy link
Contributor

can be. I am myself using tons of .js files after I upgraded. Let's see if maintainers would like the fix merged or leave it as it is.

@motiz88
Copy link
Contributor

motiz88 commented Mar 1, 2023

I think the ideal solution here (for the cases where static type checking isn't enough) is for the native implementation to throw a proper JS error, including a call stack, when it tries to use that provided value. This should be doable under the new architecture. That way we don't have to add redundant checks on the JS side.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 31, 2023
@github-actions
Copy link

github-actions bot commented Sep 7, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Alert Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants