I want to collect error messages from all types of failing queries (in order to store them in our database).
For some resources this works fine by accessing the .error values, but for "Run JS Code" and "Query JSON with SQL" I wasn't able to find a way to access the error message.
Here an example: The "Run JS Code" fails and throws an error message, but I couldn't find a way to access this error message (for example inside a failed event).
Is there any solution for this?
At the moment we have a couple of issues in our backlog to address updating the
In the case of JS queries you can build in a custom error handler using a try...catch block.
For Query JSON with SQL queries, it may be a bit trickier - you could check, for instance, that the query data is
undefined after it has run as an indicator that there may have been an error, though that obfuscates any messaging. Are there any particular kinds of errors you're looking to catch?
In general my goal is to monitor all queries for errors. We are going to have more developers working on the apps and I need an overall control of queries failing so that they can be address properly. Also because users are often ignoring errors in the frontend, leaving them be without reporting them to the development team. By logging all sorts of errors in the database, we can be proactive rather than reactive on user complaints.
I now went with your suggestion of the try/catch-block. This works in general. Thank you for that advice.
There are still two issues I am facing:
- Inside a JS query, how do I know the name of the JS query? Is it possible to know it? Of course I would like to store into my database not only the error but also the name of the JS query that caused the error. self.id or self.name didn't work. Is there any other way?
- I further would need a list of all JS queries. The try/catch block catches certain errors, but not JS syntax errors. I found a way how to validate a JS query for syntax error. I don't want to do this during runtime, but rather with a logic where I get a list of ALL JS queries of an app and validate one by one with a loop. Is there any way how I can get programmatically a list of all JS queries? We do have an on-premise installation, is there maybe a list of the JS queries available inside the Retool database?
There may be a workaround here I'm unaware of but as far as I know, we don't support either
The closest I can see for 1) is to reference the
retoolContext.appName so you at least know the name of the app it's in.
For 2) apps are currently stored in a backend server associated with your instance that's separate from the Postgres DB and, at the moment, doesn't have an exposed API that you can use to query for app data.
It is on our radar to build in global error handling and we'll let you know here if and when that's included, I'm not thinking of any better approaches though.