Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option handlePromiseRejection #300

Merged
merged 3 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ matrix:
- addon-google_apis-google-16
env: LANE='android'
script: .travis/run.sh
if: env(TRAVIS_SECURE_ENV_VARS) = true

- language: objective-c
os: osx
Expand All @@ -51,7 +50,6 @@ matrix:
- virtualenv ~/virtualenv
- source ~/virtualenv/bin/activate
script: .travis/run.sh
if: env(TRAVIS_SECURE_ENV_VARS) = true

- language: node_js
node_js: 8
Expand Down
5 changes: 5 additions & 0 deletions .travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ if [ "$LANE" = "node" ]; then
cd example
npm run test
else
if [ "$TRAVIS_SECURE_ENV_VARS" != "true" ] ; then
echo "SKIPPING device tests since not secure env"
exit 0
fi

cd appium
bundle install
pip wheel --wheel-dir wheelhouse -r requirements.txt
Expand Down
3 changes: 2 additions & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ These are functions you can call in your javascript code:
Sentry.config("___DSN___", {
deactivateStacktraceMerging: false, // default: true | Deactivates the stacktrace merging feature
logLevel: SentryLog.Debug, // default SentryLog.None | Possible values: .None, .Error, .Debug, .Verbose
disableNativeIntegration: false // default: false | Deactivates the native integration and only uses raven-js
disableNativeIntegration: false, // default: false | Deactivates the native integration and only uses raven-js
handlePromiseRejection: true // default: true | Handle unhandled promise rejections
// sampleRate: 0.5 // default: 1.0 | Only set this if you don't want to send every event so e.g.: 0.5 will send 50% of all events
// These two options will only be considered if stacktrace merging is active
// Here you can add modules that should be ignored or exclude modules
Expand Down
3 changes: 2 additions & 1 deletion lib/RavenClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class RavenClient {
Raven.addPlugin(
require('./raven-plugin'),
{
nativeClientAvailable: Sentry.isNativeClientAvailable()
nativeClientAvailable: Sentry.isNativeClientAvailable(),
handlePromiseRejection: this.options.handlePromiseRejection
},
data => {
if (Sentry.options.internal) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const Sentry = {
Sentry.options = {
logLevel: SentryLog.None,
instrument: false,
disableNativeIntegration: false
disableNativeIntegration: false,
handlePromiseRejection: true
};
Object.assign(Sentry.options, options);
return Sentry;
Expand Down
74 changes: 42 additions & 32 deletions lib/raven-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ function reactNativePlugin(Raven, options, internalDataCallback) {
Raven.setTransport(reactNativePlugin._transport);

// Check for a previously persisted payload, and report it.
reactNativePlugin._restorePayload().then(function(payload) {
options.onInitialize && options.onInitialize(payload);
if (!payload) return;
Raven._sendProcessedPayload(payload, function(error) {
if (error) return; // Try again next launch.
reactNativePlugin._clearPayload();
});
})['catch'](function() {});
reactNativePlugin
._restorePayload()
.then(function(payload) {
options.onInitialize && options.onInitialize(payload);
if (!payload) return;
Raven._sendProcessedPayload(payload, function(error) {
if (error) return; // Try again next launch.
reactNativePlugin._clearPayload();
});
})
['catch'](function() {});

Raven.setShouldSendCallback(function(data, originalCallback) {
if (!(FATAL_ERROR_KEY in data)) {
Expand All @@ -99,11 +102,14 @@ function reactNativePlugin(Raven, options, internalDataCallback) {
var origError = data[FATAL_ERROR_KEY];
delete data[FATAL_ERROR_KEY];

reactNativePlugin._persistPayload(data).then(function() {
defaultHandler(origError, true);
handlingFatal = false; // In case it isn't configured to crash.
return null;
})['catch'](function() {});
reactNativePlugin
._persistPayload(data)
.then(function() {
defaultHandler(origError, true);
handlingFatal = false; // In case it isn't configured to crash.
return null;
})
['catch'](function() {});

return false; // Do not continue.
});
Expand All @@ -119,20 +125,22 @@ function reactNativePlugin(Raven, options, internalDataCallback) {
(ErrorUtils.getGlobalHandler && ErrorUtils.getGlobalHandler()) ||
ErrorUtils._globalHandler;

// Track unhandled promise rejections
var tracking = require('promise/setimmediate/rejection-tracking');
tracking.disable();
tracking.enable({
allRejections: true,
onUnhandled: function(id, error) {
var captureOptions = {
timestamp: new Date() / 1000,
type: 'Unhandled Promise Rejection'
};
Raven.captureException(error, captureOptions);
},
onHandled: function() {}
});
if (options.handlePromiseRejection) {
// Track unhandled promise rejections
var tracking = require('promise/setimmediate/rejection-tracking');
tracking.disable();
tracking.enable({
allRejections: true,
onUnhandled: function(id, error) {
var captureOptions = {
timestamp: new Date() / 1000,
type: 'Unhandled Promise Rejection'
};
Raven.captureException(error, captureOptions);
},
onHandled: function() {}
});
}

ErrorUtils.setGlobalHandler(function(error, isFatal) {
var captureOptions = {
Expand Down Expand Up @@ -189,11 +197,13 @@ reactNativePlugin._persistPayload = function(payload) {
*/
reactNativePlugin._restorePayload = function() {
var AsyncStorage = require('react-native').AsyncStorage;
var promise = AsyncStorage.getItem(ASYNC_STORAGE_KEY).then(function(payload) {
return JSON.parse(payload);
})['catch'](function() {
return null;
});
var promise = AsyncStorage.getItem(ASYNC_STORAGE_KEY)
.then(function(payload) {
return JSON.parse(payload);
})
['catch'](function() {
return null;
});
// Make sure that we fetch ASAP.
var RCTAsyncSQLiteStorage = NativeModules.AsyncSQLiteDBStorage;
var RCTAsyncRocksDBStorage = NativeModules.AsyncRocksDBStorage;
Expand Down