SQLpage icon indicating copy to clipboard operation
SQLpage copied to clipboard

on_error.sql handler for errors

Open andrewsinnovations opened this issue 6 months ago • 2 comments

What are you building with SQLPage ?

An application in the healthcare industry.

What is your problem ?

We would like to log errors that our users encounter and potentially create tickets in our support system when a user receives an error message.

Describe the solution you'd like

It would be great if there was an on_error.sql handler that received the error message, URL, sqlpage.variables() and also the backtrace. It would be cool if we could write this with SQL as any other SQL page, and insert the log into our database and potentially execute other operations like fetch() to call out to other systems (to send an email, create a ticket, etc.)

Describe alternatives you've considered

There are no really good alternatives currently available because in production environment we do not get the backtrace in error.handlerbars, so we can't even log the error somehow from the user's browser. The error is essentially lost.

Additional context

I've taken a stab in the rust at creating this as pull request, but I cannot find a good place in the code to insert this handler. If you could give some ideas as to where a good handler code might live, I could submit as a PR.

andrewsinnovations avatar Jun 26 '25 05:06 andrewsinnovations

Hello @andrewsinnovations thanks for this request and for your past contributions. Would be great to discuss this and figure out the best way to build it. Feel free to email me [email protected] to set up a quick call

alexisrc1 avatar Jun 27 '25 07:06 alexisrc1

@alexisrc1 I've been delayed in responding. I'm not sure I can provide the best way to build it as I have very limited abilities in rust. I took a stab at writing the change and could not successfully figure out how to evaluate a new handler when the "stream" is in an error handler mode. The only place I could find was the on_error in the renderer, that's where the backtrace is generated. I need to become more familiar with rust debugging in order to have it call that handler on an error event.

andrewsinnovations avatar Jul 09 '25 18:07 andrewsinnovations