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

fix(promise): Swallowed rejections warnings, use `console.error` for logging rejections in dev and prod

Open krystofwoldrich opened this issue 8 months ago • 1 comments

Summary:

This PR fixes logging of rejections, which stopped working with the transition from using LogBox for warnings to directing users to use React Native Debugger, where warnings can be viewed in the Console tab.

Rejected promises before this PR used LogBox.addLog with the level: warn directly without console.warn, thus user were notified to open debugger to view a warning (after rejected promise), but there were no warnings in the console.

This PR uses console.error for all rejections which better aligns with the browsers behavior. The message is also updated to better match with what users know from browsers.

Rejected Promise in Chrome

Screenshot 2025-05-25 at 14 50 25

Rejected Promise in React Native after this PR

Screenshot 2025-05-26 at 0 07 07

LogBox After This PR

Changelog:

[GENERAL] [FIXED] - Swallowed promise rejections warnings

Test Plan:

Use Promise.reject and observe that the rejection is now shown symbolicated in LogBox and also printed in React Native Debugger Console.

<Button
  title="Uncaught Promise Rejection"
  onPress={() => {
    Promise.reject(new Error('This is an uncaught promise rejection!'));
  }}
/>

Future

Ideally the rejection stack is symbolicated in dev, but I would prefer that to be solved in a separate PR.

Example

Screenshot 2025-05-26 at 0 22 54

krystofwoldrich avatar May 26 '25 07:05 krystofwoldrich

@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar May 27 '25 10:05 facebook-github-bot

Hey @krystofwoldrich, I'm on it. Thank you for the contribution. We have several conflicting changes in this area and we are trying to synchronize between them. I think it should take a few weeks to merge it.

vzaidman avatar May 30 '25 15:05 vzaidman

Got it, thank you for the update @vzaidman.

krystofwoldrich avatar Jun 02 '25 14:06 krystofwoldrich

Hi @vzaidman, will the conflicting changes be part of 0.81 release?

krystofwoldrich avatar Jul 15 '25 10:07 krystofwoldrich

I'm working on it now. Probably 0.82. Depends on if I can pick it.

vzaidman avatar Jul 15 '25 12:07 vzaidman

@vzaidman merged this pull request in facebook/react-native@c4082c9ce208a324c2d011823ca2ba432411aafc.

facebook-github-bot avatar Jul 17 '25 16:07 facebook-github-bot

@krystofwoldrich this is merged now. Will be available in 0.82. There were some problems getting it to play nicely with out tests internally as they suddenly started to ignore errors and raised console.errors which were failing tests in some cases.

vzaidman avatar Jul 17 '25 16:07 vzaidman

@vzaidman Thanks for the details and the update.

krystofwoldrich avatar Jul 17 '25 16:07 krystofwoldrich

Fails
:no_entry_sign:

:clipboard: Missing Changelog - Please add a Changelog to your PR description. See Changelog format

Warnings
:warning: :exclamation: JavaScript API change detected - This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. Please include a clear changelog message. This change will be subject to extra review.

This change was flagged as: BREAKING

Generated by :no_entry_sign: dangerJS against f6ccd8dbca12523b4734e9eb445d6e56cb2771b4

react-native-bot avatar Jul 17 '25 16:07 react-native-bot

I've updated the summary with how I modified the initially proposed code and added some examples.

vzaidman avatar Jul 17 '25 16:07 vzaidman