bugsnag / bugsnag-react-native

Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
https://docs.bugsnag.com/platforms/react-native
MIT License
369 stars 121 forks source link

`Client.notify()` docs seem inaccurate. #447

Closed jarod-legault closed 4 years ago

jarod-legault commented 4 years ago

Description

I am trying to create a Bugsnag report in a React Native project with extra data (metadata).

Issue

I followed the Bugsnag docs and tried both methods under "Customizing Diagnostic Data":

// Sending a metaData property in opts
bugsnagClient.notify(new Error('Something broke!'), {
  metaData: {
    'special info': {
      request_id: 12345,
      message_id: 854
    }
  }
})
// Adding metaData via report methods
bugsnagClient.notify(new Error('Something broke!'), {
  beforeSend: (report) => {
    report.updateMetaData('special info', {
      request_id: 12345,
      message_id: 854
    })
  }
})

and I was getting this error:

TypeError n is not a function. (In 'n(f)', 'n' is an instance of Object) 
    node_modules/bugsnag-react-native/lib/Bugsnag.js:107:19 
    node_modules/regenerator-runtime/runtime.js:62:44 tryCatch
    node_modules/regenerator-runtime/runtime.js:296:30 
    node_modules/regenerator-runtime/runtime.js:62:44 tryCatch
    node_modules/regenerator-runtime/runtime.js:152:28 invoke
    node_modules/regenerator-runtime/runtime.js:195:17 
    node_modules/promise/setimmediate/core.js:45:7 tryCallTwo
    node_modules/promise/setimmediate/core.js:200:23 doResolve
    node_modules/promise/setimmediate/core.js:66:12 Promise
    node_modules/regenerator-runtime/runtime.js:194:27 callInvokeWithMethodAndArg
    node_modules/regenerator-runtime/runtime.js:217:12 _invoke
    node_modules/regenerator-runtime/runtime.js:241:13 async
    node_modules/bugsnag-react-native/lib/Bugsnag.js:86:177 notify
    ...

When I check the index.d.ts file in the Bugsnag directory, I see that the second parameter in the notify method is beforeSendCallback (not opts as the docs say). I also see that there is no report.updateMetaData method, but there is a report.addMetadata method. Based on what I found in index.d.ts, I was able to get my code working this way:

bugsnagClient.notify( new Error( errorTitle ), report => {
   report.addMetadata( "error info", "errorData", errorData );
} );

Are the docs inaccurate? Or am I not understanding how to use the notify method properly?

Environment

Library versions:

├── bugsnag-react-native@2.23.6 
├── UNMET PEER DEPENDENCY react-native@0.59.10 
└── react-native-code-push@5.5.3 

Example code snippet

bugsnagClient.notify( new Error( errorTitle ), {
      metaData: {
        "error info": {
          error:      error,
          errorTitle: errorTitle,
          errorData:  errorData
        }
      }
    } );
Error messages: ``` TypeError n is not a function. (In 'n(f)', 'n' is an instance of Object) node_modules/bugsnag-react-native/lib/Bugsnag.js:107:19 node_modules/regenerator-runtime/runtime.js:62:44 tryCatch node_modules/regenerator-runtime/runtime.js:296:30 node_modules/regenerator-runtime/runtime.js:62:44 tryCatch node_modules/regenerator-runtime/runtime.js:152:28 invoke node_modules/regenerator-runtime/runtime.js:195:17 node_modules/promise/setimmediate/core.js:45:7 tryCallTwo node_modules/promise/setimmediate/core.js:200:23 doResolve node_modules/promise/setimmediate/core.js:66:12 Promise node_modules/regenerator-runtime/runtime.js:194:27 callInvokeWithMethodAndArg node_modules/regenerator-runtime/runtime.js:217:12 _invoke node_modules/regenerator-runtime/runtime.js:241:13 async node_modules/bugsnag-react-native/lib/Bugsnag.js:86:177 notify ```
jcurlier commented 4 years ago

+1

abigailbramble commented 4 years ago

Hi @jarod-legault , @jcurlier

We have separate documentation for React Native and Javascript. The link to the documentation and examples above are from our Javascript docs.

Information for adding diagnostic data in React Native is available here: https://docs.bugsnag.com/platforms/react-native/react-native/#sending-diagnostic-data

The example looks like this:

bugsnag.notify(error, function(report) {
  report.metadata = { "account": {
    "company": "Acme Co",
    "id": 123
    }
  }
});

Additional information on customising error reports for React Native is available here: https://docs.bugsnag.com/platforms/react-native/react-native/customizing-error-reports/#adding-custom-diagnostics

With this as an example:

bugsnag.notify(error, (report) => {
  report.metadata.account = {"name": "Acme Co."};
});
jarod-legault commented 4 years ago

Hi @jarod-legault , @jcurlier

We have separate documentation for React Native and Javascript. The link to the documentation and examples above are from our Javascript docs.

Information for adding diagnostic data in React Native is available here: https://docs.bugsnag.com/platforms/react-native/react-native/#sending-diagnostic-data

The example looks like this:

bugsnag.notify(error, function(report) {
  report.metadata = { "account": {
    "company": "Acme Co",
    "id": 123
    }
  }
});

Additional information on customising error reports for React Native is available here: https://docs.bugsnag.com/platforms/react-native/react-native/customizing-error-reports/#adding-custom-diagnostics

With this as an example:

bugsnag.notify(error, (report) => {
  report.metadata.account = {"name": "Acme Co."};
});

Wow, I can't believe I missed that. Thanks so much, @phillipsam!