Skip to content

Commit b064094

Browse files
davidaureliofacebook-github-bot-3
authored andcommitted
Add support for promise rejection tracking
Summary: Adds support for tracking unhandled rejections with `console.warn` (= yellow box). I will create a follow-up with proper error stack formatting. related: facebook#4971 fixes: facebook#4045, facebook#4142 public {F59857438} {F59857439} Reviewed By: bestander Differential Revision: D2803126 fb-gh-sync-id: 376b33e42a967675a04338cbff3ec315a77d1037
1 parent 2b09614 commit b064094

File tree

3 files changed

+122
-102
lines changed

3 files changed

+122
-102
lines changed

Libraries/Promise.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@
2525
global.setImmediate = require('setImmediate');
2626
var Promise = require('promise/setimmediate/es6-extensions');
2727
require('promise/setimmediate/done');
28+
if (__DEV__) {
29+
require('promise/setimmediate/rejection-tracking').enable({
30+
allRejections: true,
31+
onUnhandled: (id, error) => {
32+
const {message, stack} = error;
33+
const warning =
34+
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
35+
(message == null ? '' : `${message}\n`) +
36+
(stack == null ? '' : stack);
37+
console.warn(warning);
38+
},
39+
onHandled: (id) => {
40+
const warning =
41+
`Promise Rejection Handled (id: ${id})\n` +
42+
'This means you can ignore any previous messages of the form ' +
43+
`"Possible Unhandled Promise Rejection (id: ${id}):"`;
44+
console.warn(warning);
45+
},
46+
});
47+
}
2848

2949
/**
3050
* Handle either fulfillment or rejection with the same callback.

0 commit comments

Comments
 (0)