How to force javascript query to fail?

I have some required validation logic on a bulk table update query, wherein I want to block updates in case of error, but also not clear out the edits in the table when the errors occur (i.e. leave their changes in place, still showing as changes, so they can adjust them).

I have no issue gathering all my errors and showing them in a modal or , but I need the javascript query to fail, so the edits don't get wiped out of the table. E.g., if I have a javascript error in the query, the query fails (obviously), and all of the edits stay yellow and the save changes button remains.

I have tried return false; in the query, which of course doesn't record the query run as a failure.

How do I force retool to see the query run as a failure, programmatically?

1 Like

... of course, after about five seconds, I answer the question myself:

return Promise.reject("Invalid options");
2 Likes

@church This is similar to an earlier post of mine which did not have a satisfactory answer: Make your js query fail and trigger calling onFailure()

You mostly answer that question! return Promise.reject("Invalid options") does indeed cause onFailure to fire.

But I still do not get the message so I have no idea why is failed. Did you figure that part out as well?

Thanks and I'll mention this post on that thread.

2 Likes

@bradlymathews To surface the error (in my case, there may be several errors), I store what I want to surface into a temporary state variable. After that point, you can display an alert, a modal, or whatever you need to surface it effectively.

return Promise.reject("") no longer causes the query to fail.

// jsAddtoST
let auth = await restSTAuthent.trigger()
if (auth?.token === undefined) {
  utils.showNotification({title: 'Error',description: JSON.stringify(restSTAuthent.data), notificationType:"error"})
  return Promise.reject("")
}

restSTAuthent fails, I show the notification and return the Promise.reject, however, the js query succeeds:

Hey Brad! Ack. Did return Promise.reject("") cause your JS query to fail recently? I know our JS queries don't currently fail (and haven't previously failed), but we're prioritizing it for Q1 this year!

These don't cause JS queries to fail:
return Promise.reject('some reason') throw 'some reason' throw new Error('message')

This is a bad workaround:
return {error: 'some error text'}

I seem to remember this was working back in May '21 - that is certainly what I reported. It was probably when I was using the onSuccess/onFailure pattern. Have long since moved on to async/await pattern and I appreciate that it is being worked on!

Ooh okay, makes sense. And I’m glad it’ll be helpful! Should hopefully be soon :crossed_fingers:

Hey all, we've added functionality to allow failure conditions to work for Javascript, JSON with SQL and Parent Window queries, and will start rolling out the feature flag soon! :tada:

We want to be cautious with users who have added a failure condition for these types of queries that doesn't currently fire, and will start firing when the flag is active.

If any issues like that come in over the next few weeks of the rollout, please do let us know!

2 Likes