Replies: 1 comment 5 replies
-
|
Hello! Thank you for opening this issue, this is definitely a point we could improve on. I have access to coding agents too, so the implementation details are not really the important things to discuss here. What I am more interested about is your feedback as an user. What does your application do? Where are the errors in your application, can you give examples? How do users encounter them (bad input from them, or programming errors from you)? What would you like to be able to show them instead in each case? During development, do you find the errors useful or do you think they often miss something? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @lovasoa & Team,
Before I start, I want to thank you for the excellent work you've put into SQL-Page.
So, I've used SQL-Page to develop a feature-rich MVP, to the point that it could be used as a final product. However, one area that users have commented on is error handling and the display of errors. I'd like to propose changes that allow the developer to indicate, on a per-page basis, whether an alternative mechanism is used. I don't believe there is a mechanism to do this currently.
Now, I'm not a Rust programmer, so I asked Claude Code to come up with a proposed set of requirements and possible areas of change. I can't determine whether the latter is sensible or not, but I've included the output verbatim from my query to Claude. I hope you don't mind that I've called on our robot overlords for assistance here :-) — the intent is to make the requirements clearer and provide a better, more streamlined example than I could have put together myself.
Details
Proposal: Custom Database Error Handling in SQLPage
Background
Currently, when a database error occurs mid-page, SQLPage calls
handle_error()insrc/render.rs:845, which renders the built-inerror.handlebarscomponent and (viastop_at_first_error()insrc/webserver/database/execute_queries.rs:264) halts allfurther SQL execution. Application developers have no way to intercept, customise, or
suppress this behaviour.
User Stories
US-1 — Custom error display (inline component)
US-2 — Custom error handler SQL file
US-3 — Error details in the handler
US-4 — Continue-on-error
US-5 — Default behaviour unchanged
Proposed SQL API
Declare an error handler (header phase — must come before any body component)
Error handler SQL file (
partials/my_error.sql)The file is executed with the following variables automatically set:
$error_message$sqlstate$query_numberOption B — inline component usage
When
handleris a component name rather than a.sqlfile path, the server rendersthat component with error fields injected automatically as the component's top-level row:
description = error_message,color = 'danger',title = 'Error'.Architectural Analysis
How
stop_at_first_errorandhandle_errorinteract todayThe problem:
stop_at_first_error()is applied beforebuild_response_header_and_stream()runs, so the header phase has no chance to configure error-handling behaviour.
Proposed execution flow
Implementation Plan (Rust — minimal changes)
1. New
ErrorHandlerConfigtypeAdd to
src/render.rs(or a small companion file):parse_error_link()distinguishes file from component name by checking whetherhandlerends in
.sql.2.
HeaderComponent::ErrorLink—src/render.rs(HeaderContext)Add
ErrorLinkto theHeaderComponentenum and handle it inhandle_row():This follows exactly the same pattern as
StatusCode,Authentication,Redirect, etc.3.
RequestContextgainserror_handler: Option<ErrorHandlerConfig>Threads the config from the header phase into the body renderer so
HtmlRenderContextcan consult it.
4. Move
stop_at_first_error—src/webserver/http.rs:277Remove the unconditional application:
Add a conditional version inside
build_response_header_and_stream, at thebody-phase transition point, after the error handler config is known:
The stream would need to be type-erased (boxed) here; this pattern is already used
elsewhere in the codebase.
5. Modify
handle_error()—src/render.rs:845run_error_handler_sql()mirrors the internals of the existingrun_sqlSQLPage function(
src/webserver/database/sqlpage_functions/functions.rs:712). It needs access toExecutionContextand a database connection; see Open Questions below for the preferredway to thread these into
HtmlRenderContext.extract_error_details()is a small helper that inspects theanyhow::Errorchain forsqlxerror fields (SQLState, message text, etc.).Files Changed
src/render.rsErrorHandlerConfig;HeaderComponent::ErrorLink; newhandle_error_custom()src/webserver/http.rsstop_at_first_error(); add conditional at body-phase transitionsrc/webserver/database/execute_queries.rsWhat Is Explicitly Reused (no new templates needed)
alertcomponentmodalcomponenthtmlcomponentrun_sqlpattern$error_messageetc. to the handler fileerror_linksits alongsidestatuscode,authentication,redirectOpen Questions for the Maintainer
Type erasure on the stream — moving
stop_at_first_errorto the body-phasetransition requires boxing the stream (
Box<dyn Stream<...>>). Is this acceptable,or is there a preferred pattern for stream-type erasure in this codebase?
HtmlRenderContextaccess toExecutionContextand DB connection — for the SQLfile handler option, the renderer needs these. One option is to pass them into
handle_error()as parameters; another is to store them on the context atconstruction time. What fits the ownership model better?
Scope of
error_link— should it be header-only (one global setting per page),or allowed mid-page to change the handler for subsequent queries? Header-only is
simpler and consistent with
statuscode/authentication.Error in the error handler — if the error handler SQL file itself fails, what
should happen? Suggestion: fall back silently to the built-in
errorcomponent,always, to prevent infinite error loops.
Full Example — Dashboard with Continue-on-Error
Summary
This proposal requires approximately 3–4 medium Rust changes concentrated in
src/render.rsandsrc/webserver/http.rs. It introduces no new Handlebars templatefiles, reuses the existing header-phase component pattern and the
run_sqlexecutionpattern, and is fully backwards-compatible — pages without an
error_linkdeclarationbehave exactly as today.
Beta Was this translation helpful? Give feedback.
All reactions