<commit_before>/*
* Automatically notifies Bugsnag when an unhandled promise rejection happens in React Native
*/

/* global __DEV__ */

const rnPromise = require('promise/setimmediate/rejection-tracking')

module.exports = {
  load: (client) => {
    if (!client._config.autoDetectErrors || !client._config.enabledErrorTypes.unhandledRejections) return () => {}
    rnPromise.enable({
      allRejections: true,
      onUnhandled: (id, error) => {
        const event = client.Event.create(error, false, {
          severity: 'error',
          unhandled: true,
          severityReason: { type: 'unhandledPromiseRejection' }
        }, 'promise rejection tracking', 1)
        client._notify(event)
        // adding our own onUnhandled callback means the default handler doesn't get called, so make it happen here
        if (typeof __DEV__ !== 'undefined' && __DEV__) rnInternalOnUnhandled(id, error)
      }
    })
    return () => rnPromise.disable()
  }<commit_msg>patch hermes promise if available<commit_after>/*
* Automatically notifies Bugsnag when an unhandled promise rejection happens in React Native
*/

/* global __DEV__ */

const rnPromise = require('promise/setimmediate/rejection-tracking')

module.exports = {
  load: (client) => {
    if (!client._config.autoDetectErrors || !client._config.enabledErrorTypes.unhandledRejections) return () => { }

    if (global && global.HermesInternal && global.HermesInternal.hasPromise()) {
      const HermesPromise = global.Promise;

      console.log("Hermes promise found, monkey patching...")

      if (__DEV__) {
        if (typeof HermesPromise !== 'function') {
          console.error('HermesPromise does not exist');
        }

        global.HermesInternal.enablePromiseRejectionTracker({
          allRejections: true,
          onUnhandled: (id, rejection = {}) => {
            const event = client.Event.create(rejection, false, {
              severity: 'error',
              unhandled: true,
              severityReason: { type: 'unhandledPromiseRejection' }
            }, 'promise rejection tracking', 1)

            client._notify(event)

            // adding our own onUnhandled callback means the default handler doesn't get called, so make it happen here
            if (typeof __DEV__ !== 'undefined' && __DEV__) rnInternalOnUnhandled(id, error)
          }
        });
      }

      // TODO: Cleanup hermes promise
      // return () => HermesPromise
      return
    }

    console.log("Hermes promise not found, monkey patching rnPromise...")

    rnPromise.enable({
      allRejections: true,
      onUnhandled: (id, error) => {
        const event = client.Event.create(error, false, {
          severity: 'error',
          unhandled: true,
          severityReason: { type: 'unhandledPromiseRejection' }
        }, 'promise rejection tracking', 1)
        client._notify(event)
        // adding our own onUnhandled callback means the default handler doesn't get called, so make it happen here
        if (typeof __DEV__ !== 'undefined' && __DEV__) rnInternalOnUnhandled(id, error)
      }
    })

    return () => rnPromise.disable()
  }
{'fraction_non_alphanumeric': 0.11231652839821314, 'fraction_numerical': 0.0009572431397574984, 'mean_word_length': 2.732142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '17255', 'n_tokens_mistral': 898, 'n_tokens_neox': 867, 'n_words': 232}