Skip to content

Commit

Permalink
Add support for promise rejection tracking
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davidaurelio authored and christopherdro committed Jan 20, 2016
1 parent 5a3c4dc commit 3039cd0
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 102 deletions.
20 changes: 20 additions & 0 deletions Libraries/Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@
global.setImmediate = require('setImmediate');
var Promise = require('promise/setimmediate/es6-extensions');
require('promise/setimmediate/done');
if (__DEV__) {
require('promise/setimmediate/rejection-tracking').enable({
allRejections: true,
onUnhandled: (id, error) => {
const {message, stack} = error;
const warning =
`Possible Unhandled Promise Rejection (id: ${id}):\n` +
(message == null ? '' : `${message}\n`) +
(stack == null ? '' : stack);
console.warn(warning);
},
onHandled: (id) => {
const warning =
`Promise Rejection Handled (id: ${id})\n` +
'This means you can ignore any previous messages of the form ' +
`"Possible Unhandled Promise Rejection (id: ${id}):"`;
console.warn(warning);
},
});
}

/**
* Handle either fulfillment or rejection with the same callback.
Expand Down
Loading

0 comments on commit 3039cd0

Please sign in to comment.