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

For me, this does not work.

let test;
try {
  test = await query.trigger();
}
catch(error) {
  return "failed";
}
return test;

The catch block does not seem to be picking up on the error from the query. The catch block is never executed I'm not sure if this issue(which I thought this original post was about) is being resolved somehow by the information in your last post @Tess

Hi there!

The bug fix specifically addresses the issue where the error property wasn't getting updated and therefore couldn't be referenced in failure event handlers

Prior to the bug fix, the error property remained undefined, so you couldn't reference it in the failure handler:

Now that we shipped the fix, you can at least reference the error property:

We still have an outstanding request for the trigger() method to reject on failure so error can be caught in try/catch

"We still have an outstanding request for the trigger() method to reject on failure so error can be caught in try/catch"

Any updates on this?

Hi @JasperCreationss,

Thank you for bumping this!

It looks like the ticket is marked as "ready for work" but at a low priority.

I can add a +1 for you onto the ticket and hopefully it can get picked up in our next engineering sprint where the IDE team has some open bandwidth :crossed_fingers:

1 Like

Check out this post by @TobiasOhlsson. This should be an answer to what you're looking for. The way he went about it has totally changed how handle all my promises and possible failures.
Big Kudos to him!

3 Likes