JavaScript Rollbar Unknown Unhandled Rejection Error Getting Reason From Event

In your JavaScript application, If you see the following error in your Rollbar:


(unknown): "[unhandledrejection] error getting `reason` from event"

Then it most probably means that reject of a Promise is being called, and you have not provided a catch block at the end to catch it.

For example:

userId = 7;

return new Promise((resolve, reject) => {
  return getUser(7, resolve, reject);
})
  .then(() => {
    // do something on success
  });

I have seen the above pattern in React applications where redux-saga is used. We create our own promise and pass resolve and reject functions to the saga method via redux action. In the saga, if the request is successful, we call resolve, otherwise reject. But since we have not provided a catch block, the Rollbar error occurs.

To fix this, provide a catch block:

userId = 7;

return new Promise((resolve, reject) => {
  return getUser(7, resolve, reject);
})
  .then(() => {
    // do something on success
  })
  .catch(e => console.log(e));

This issue is not exclusive to redux-saga library, or ReactJS applications. It may occur in any JavaScript application due to wrong handling of reject/catch of a Promise. For specific troubleshooting, open the Rollbar error detail page and check the traceback section thoroughly till bottom.

See also