expo: [expo-localization] Exception: Unsupported ISO 3166 country: es_419

Minimal reproducible example

https://gist.github.com/andresribeiro/569e4d70afe1778e8f2541e301433017

Summary

The following error appears on Play Console pre-launch report:

Exception com.facebook.react.common.JavascriptException: Error: Call to function 'ExpoLocalization.getLocales' has been rejected.
→ Caused by: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: es_419, js engine: hermes, stack:
_construct@1:105491
Wrapper@1:105136
_createSuperInternal@1:645189
CodedError@1:645474
findBestAvailableLanguage@1:703297
getBestAvailableLanguage@1:703599
setBestAvailableDayJsLocale@1:692514
anonymous@1:692458
loadModuleImplementation@1:73062
guardedLoadModule@1:72611
metroRequire@1:72239
anonymous@1:690154
loadModuleImplementation@1:73062
guardedLoadModule@1:72611
metroRequire@1:72239
anonymous@1:79390
loadModuleImplementation@1:73062
guardedLoadModule@1:72568
metroRequire@1:72239
global@1:71823
  at com.facebook.react.modules.core.ExceptionsManagerModule.reportException (ExceptionsManagerModule.java:72)
  at java.lang.reflect.Method.invoke
  at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
  at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:188)
  at com.facebook.jni.NativeRunnable.run
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
  at android.os.Looper.loop (Looper.java:223)
  at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228)
  at java.lang.Thread.run (Thread.java:923)

It might be related to these 2 issues from react-native-localize:

https://github.com/zoontek/react-native-localize/issues/31 https://github.com/zoontek/react-native-localize/issues/36

Environment

System: OS: Linux 5.4 Linux Mint 20.3 (Una) Shell: 5.8 - /usr/bin/zsh Binaries: Node: 19.7.0 - /usr/bin/node Yarn: 1.22.19 - /usr/bin/yarn npm: 9.5.0 - /usr/bin/npm Watchman: 20220605.192726.0 - /usr/local/bin/watchman npmPackages: expo: ~48.0.4 => 48.0.4 react: 18.2.0 => 18.2.0 react-native: 0.71.3 => 0.71.3 npmGlobalPackages: eas-cli: 3.7.2 expo-cli: 6.3.2 Expo Workflow: managed

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

It’s hard to provide a reproducible example, but I decided to run an emulator, which let me change the locale through adb commands. The faulty locale is named Latin American Spanish but I was not able to see this option through the settings UI. I guess some phones are shipped with this option enabled or added on custom Android OS phones.

Using an emulator let me change this in terminal. So I decided to test it on an old Android version (11) by running these commands

adb root
adb shell "setprop persist.sys.locale es-419; setprop ctl.restart zygote"

Navigating to the language setting, I can finally see that option, which wasn’t available before, and that my phone is using Latin American Spanish

2024-02-16_15-14

Now I did 2 different console.log, one with the deprecated locale constant and one with the new getLocales() method. The deprecated one is correctly showing the locale but not the new one, showing an empty array. And so my code was using getLocales() method in both example after these 2 different logs, hence crashing my application

2024-02-16_15-14_1 2024-02-16_15-13

Sad because it’s even included in documentation examples https://github.com/expo/expo/blob/76fad0fe281f3517cb3a5375c9854541ff66b781/packages/expo-localization/build/Localization.types.d.ts#L67-L73

We are having this problem as well. These are the observations I’ve made so far about the issue:

  • It seems that the country code is missing or not an ISO country code for the exceptions we’re getting. Example: es_IC, en, pl_SP, es_419, nl, ar_XB
  • The country code is supposed to be optional, but it looks like Java throws an exception if it’s missing or incorrect
  • There was a similar error for react-native-localize Issue 31, and the fix was to add a check to validate the country code

Perhaps a similar check is needed here?

@newfylox i’ll try to follow those steps and see if I can reproduce – seems to be a fairly good repro, thank you!

Same issue here for ar EXPO 48:

Exception com.facebook.react.common.JavascriptException: Error: Call to function ‘ExpoLocalization.getLocales’ has been rejected. → Caused by: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: ar, js engine: hermes, stack: _construct@1:126614 Wrapper@1:126259 _createSuperInternal@1:668274 CodedError@1:668559 _handleAppStateChange@1:2231905 anonymous@1:645128 emit@1:115114 __callFunction@1:120571 anonymous@1:119079 __guard@1:120018 callFunctionReturnFlushedQueue@1:119037 at com.facebook.react.modules.core.ExceptionsManagerModule.reportException (ExceptionsManagerModule.java:72) at java.lang.reflect.Method.invoke at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:188) at com.facebook.jni.NativeRunnable.run at android.os.Handler.handleCallback (Handler.java:942) at android.os.Handler.dispatchMessage (Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27) at android.os.Looper.loopOnce (Looper.java:201) at android.os.Looper.loop (Looper.java:288) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228) at java.lang.Thread.run (Thread.java:1012)

image

@andresribeiro - that isn’t a valid reproducible example, you should share a link to a repository that we can clone and run and see this issue. it’d be helpful if you can add that to this issue.

that said, it seems that there may be an additional case that we need to handle with getLocales(). @aleqsio - is there enough information here for you to go off of?