expo icon indicating copy to clipboard operation
expo copied to clipboard

Uncaught Promises Not Logged / Logbox not visible

Open robgraeber opened this issue 11 months ago • 3 comments

Minimal reproducible example

https://github.com/robgraeber/rn-test

What platform(s) does this occur on?

iOS

Where did you reproduce the issue?

in Expo Go

Summary

It seems like Expo is not logging uncaught promises, any uncaught errors in an async function fail silently. I've tracked it down to here: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/promiseRejectionTrackingOptions.js#L48. console.warn() can successfully log and display a logbox if I edit the code there but LogBox.addLog() seems to do nothing.

For the reproduction example, it's using the base create-expo-app with a simple button with an async onPress: https://github.com/robgraeber/rn-test/blob/main/app/(tabs)/index.tsx#L25

Environment

expo-env-info 1.2.2 environment info:
    System:
      OS: macOS 15.1
      Shell: 3.6.0 - /usr/local/bin/fish
    Binaries:
      Node: 22.11.0 - /usr/local/bin/node
      Yarn: 1.22.19 - ~/.yarn/bin/yarn
      npm: 10.9.0 - /usr/local/bin/npm
      Watchman: 2025.04.07.00 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.10.2 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 24.2, iOS 18.2, macOS 15.2, tvOS 18.2, visionOS 2.2, watchOS 11.2
    IDEs:
      Android Studio: 2022.1 AI-221.6008.13.2211.9514443
      Xcode: 16.2/16C5032a - /usr/bin/xcodebuild
    npmPackages:
      expo: ~52.0.46 => 52.0.46 
      expo-router: ~4.0.20 => 4.0.20 
      react: 18.3.1 => 18.3.1 
      react-dom: 18.3.1 => 18.3.1 
      react-native: 0.76.9 => 0.76.9 
      react-native-web: ~0.19.13 => 0.19.13 
    npmGlobalPackages:
      eas-cli: 16.0.0
      expo-cli: 6.3.12
    Expo Workflow: managed

Expo Doctor Diagnostics

15/15 checks passed. No issues detected!

robgraeber avatar Apr 25 '25 16:04 robgraeber

This happens because errors thrown in asynchronous functions (async) inside React Native callbacks are not caught by the same global error mechanism as synchronous errors. The error thrown in the asynchronous onPress is "lost" and does not appear in the console.

To catch and log errors in asynchronous functions, use try/catch inside the callback. Example:

<TouchableOpacity
  onPress={async () => {
    try {
      throw new Error("test error");
    } catch (e) {
      console.error(e);
    }
  }}
>
  <Text style={{ color: "white" }}>THROW ERROR (ASYNC)</Text>
</TouchableOpacity>;

This way, the error will be logged correctly in the console.

I could be wrong 😅 but work haha

mensonones avatar Apr 26 '25 15:04 mensonones

@mensonones I believe it is meant to log uncaught errors, that's what https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/promiseRejectionTrackingOptions.js#L48 is for. In fact it does work in that code if it used a simple console.warn instead of logbox directly for some reason.

robgraeber avatar Apr 26 '25 16:04 robgraeber

@robgraeber - can you reproduce this in sdk 53? if you run the identical code in a blank app created with npx @react-native-community/cli init can you repro?

brentvatne avatar May 04 '25 20:05 brentvatne

asaf-s-lumen avatar Sep 06 '25 08:09 asaf-s-lumen