fix(promise): Swallowed rejections warnings, use `console.error` for logging rejections in dev and prod
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
Rejected Promise in React Native after this PR
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
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
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.
Got it, thank you for the update @vzaidman.
Hi @vzaidman, will the conflicting changes be part of 0.81 release?
I'm working on it now. Probably 0.82. Depends on if I can pick it.
@vzaidman merged this pull request in facebook/react-native@c4082c9ce208a324c2d011823ca2ba432411aafc.
@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 Thanks for the details and the update.
| 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: |
Generated by :no_entry_sign: dangerJS against f6ccd8dbca12523b4734e9eb445d6e56cb2771b4
I've updated the summary with how I modified the initially proposed code and added some examples.