react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Passing an error object o Alert crashes the app.

Open charlestbell opened this issue 2 years ago • 1 comments

Description

Hi,

I keep running into a situation where I handle an error, and pass the error message to an alert.

Example:

import { Alert } from "react-native"

...functional component

  const [error, setError] = useState();

  useEffect(() => {
    if (error) {
      Alert.alert("", error, [
        {
          text: "Okay",
          onPress: () => {
            setError(null);
          },
        },
      ]);
    }
  }, [error]);

If by accident, I pass an Error object to setError(), instead of a string, the app will crash and close completely without any error message. I know to look for it now, but it has lost me a ton of time up to this point.

Could you add a check in the Alert package, that gives a helpful error message if the input is not a string before passing it to the os and crashing everything? I think that might help future devs a lot.

Thanks.

Version

0.64.3

Output of npx react-native info

System: OS: Windows 10 10.0.19044 CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor Memory: 47.19 GB / 63.95 GB Binaries: Node: 16.13.2 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 28, 29, 30, 31 Build Tools: 28.0.3, 29.0.3, 32.0.0 System Images: android-28 | Google APIs Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom Android NDK: Not Found Windows SDK: AllowAllTrustedApps: Disabled AllowDevelopmentWithoutDevLicense: Enabled IDEs: Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085 Visual Studio: Not Found Languages: Java: 11.0.2 - C:\Users\SysAdmin\AppData\Local\jdk-11.0.2\bin\javac.EXE npmPackages: @react-native-community/cli: Not Found react: ^17.0.1 => 17.0.2 react-native: ^0.64.3 => 0.64.3 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found info React Native v0.69.1 is now available (your project is running on v0.64.3). info Changelog: https://github.com/facebook/react-native/releases/tag/v0.69.1. info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.64.3. info To upgrade, run "react-native upgrade".

Steps to reproduce

Pass a JS Error object to the Alert package where the strings go.

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

Not needed

charlestbell avatar Jul 13 '22 17:07 charlestbell

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[bot] avatar Jan 10 '23 02:01 github-actions[bot]

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

github-actions[bot] avatar Jan 18 '23 02:01 github-actions[bot]