Catch Unexpected Bugs / Errors in Failure Event Handler

I have a simple JS query that executes a function and makes no external API calls or does anything else fancy.
If there's an unexpected error or bug in my code (e.g.: null pointer exception, invalid array indexing, etc.), there's no way for me to write a try/catch statement to catch every single one of these (since they are not expected to fail).
However, I want to capture the error message for such failures when they do happen in an event handler so that I can log the error.

Is there a way to propagate the error to and retrieve it in the failure event handler?
self.error and self.data.error are both undefined when I try to access the error in either of those.

Hi @shubham,

This is a known bug. We're having the same problem in our retool error monitoring tool as well. We reproduce the error by saving the entire query state + any other global state / vars.

We use this main JS query to prepare failures to be saved

var queryData;
const queryOmits = ['dataArray', 'rawData', 'transformer', 'errorTransformer', 'query'];

const cleanedQueryData = _.omit(queryData, queryOmits);
const metadata = {
  currentUser: _.omit(_.cloneDeep(current_user), 'groups'),
  localStorage: _.cloneDeep(localStorage.values),
  retoolContext: _.cloneDeep(retoolContext),
  urlparams: _.cloneDeep(urlparams),
  viewport: _.cloneDeep(viewport),
  navigator: {
    userAgent: window.navigator.userAgent,
    platform: window.navigator.platform
  }
}

And then on each query we want to monitor we add a "Run script" failure handler:

captureFailure.trigger({
  additionalScope: {
    queryData: self
  }
})
1 Like

Hey @minijohn, thanks for responding. Is this bug being worked on? What is the estimated timeline for the fix?

Are there any workarounds I can try in the mean time?

Sorry @shubham, don't have any insights into the roadmap but I'm sure the dev team is aware and they're working it out :mechanical_arm:

Hi there! Thanks for flagging this. It is something that we're tracking and want to ship a fix for, but I don't have an eta for the fix yet :disappointed: I'll post here if I get any updates

You can now set the .error property of a JS query:

1 Like