From 1283df86da3fb3f6e102ae29ec2f95463fdb8a84 Mon Sep 17 00:00:00 2001 From: Ophir Lojkine Date: Sat, 5 Dec 2026 22:36:48 +0000 Subject: [PATCH 1/9] Show actionable HTML error reports with SQL source and request context --- CHANGELOG.md | 2 + configuration.md | 2 +- examples/CRUD - Authentication/test.hurl | 16 +- .../test.hurl | 8 +- .../test.hurl | 14 +- examples/cards-with-remote-content/test.hurl | 8 +- examples/corporate-conundrum/test.hurl | 10 +- examples/custom form component/test.hurl | 4 +- .../test.hurl | 4 +- examples/handle-404/test.hurl | 4 +- .../image gallery with user uploads/test.hurl | 8 +- examples/light-dark-toggle/test.hurl | 4 +- .../test.hurl | 6 +- examples/master-detail-forms/test.hurl | 10 +- .../test.hurl | 14 +- .../test.hurl | 6 +- examples/multiple-choice-question/test.hurl | 4 +- examples/mysql json handling/test.hurl | 8 +- examples/official-site/test.hurl | 30 ++-- .../your-first-sql-website/tutorial.md | 2 + examples/plots tables and forms/test.hurl | 6 +- examples/read-and-set-http-cookies/test.hurl | 10 +- examples/rich-text-editor/test.hurl | 6 +- examples/simple-website-example/test.hurl | 12 +- examples/single sign on/test.hurl | 4 +- examples/telemetry/test.hurl | 4 +- examples/tiny_twitter/test.hurl | 4 +- .../todo application (PostgreSQL)/test.hurl | 8 +- examples/user-authentication/test.hurl | 4 +- frontend/src/error-report.ts | 36 ++++ frontend/src/sqlpage.ts | 1 + sqlpage/templates/error.handlebars | 103 ++++++++--- src/render.rs | 76 ++++---- src/webserver/database/diagnostic.rs | 156 +++++++++++++++++ src/webserver/database/error_highlighting.rs | 46 ++--- src/webserver/database/execute_queries.rs | 50 +++--- src/webserver/database/mod.rs | 5 +- src/webserver/database/sql.rs | 52 ++---- src/webserver/database/sql/dialect.rs | 2 +- src/webserver/database/sql/statement.rs | 3 +- src/webserver/error.rs | 110 +++++++----- src/webserver/error/report.rs | 165 ++++++++++++++++++ src/webserver/http.rs | 52 ++++-- src/webserver/http_request_info.rs | 45 +++++ tests/end-to-end/fixture.ts | 2 +- .../fixtures/error-report/database.sql | 5 + .../fixtures/error-report/index.sql | 1 + .../end-to-end/fixtures/error-report/late.sql | 2 + .../end-to-end/fixtures/error-report/test.ts | 75 ++++++++ .../fixtures/error-report/tokenizer.sql | 5 + tests/errors/mod.rs | 57 +++++- ...kie_component_came_after_page_content.sql} | 0 tests/sql_test_files/mod.rs | 4 +- tests/transactions/mod.rs | 2 +- 54 files changed, 944 insertions(+), 333 deletions(-) create mode 100644 frontend/src/error-report.ts create mode 100644 src/webserver/database/diagnostic.rs create mode 100644 src/webserver/error/report.rs create mode 100644 tests/end-to-end/fixtures/error-report/database.sql create mode 100644 tests/end-to-end/fixtures/error-report/index.sql create mode 100644 tests/end-to-end/fixtures/error-report/late.sql create mode 100644 tests/end-to-end/fixtures/error-report/test.ts create mode 100644 tests/end-to-end/fixtures/error-report/tokenizer.sql rename tests/sql_test_files/component_rendering/{error_cookie_component_cannot_be_used_after_data_has_already_been_sent.sql => error_cookie_component_came_after_page_content.sql} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ca527789..b52a2d4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +- Development error pages show the failing SQL, its location, and a copyable diagnostic report. Production error pages give visitors a reference to share with the site owner. + - SQLPage reports syntax errors before running any statements in the affected SQL file. ([#1706](https://github.com/sqlpage/SQLPage/discussions/1706)) - OIDC logs focus on configuration and failures. SQLPage omits tokens, cookie values, user claims, and callback and logout query strings from OIDC diagnostics. - Standard alert descriptions have higher text contrast. diff --git a/configuration.md b/configuration.md index 9b4e504c8..3060f80cb 100644 --- a/configuration.md +++ b/configuration.md @@ -38,7 +38,7 @@ Here are the available configuration options and their default values: | `https_certificate_email` | contact@ | The email address to use when requesting a certificate. | | `https_certificate_cache_dir` | ./sqlpage/https | A writeable directory where to cache the certificates, so that SQLPage can serve https traffic immediately when it restarts. The default ignores `web_root` and `configuration_directory`. | | `https_acme_directory_url` | https://acme-v02.api.letsencrypt.org/directory | The URL of the ACME directory to use when requesting a certificate. | -| `environment` | development | The environment in which SQLPage is running. Can be either `development` or `production`. In `production` mode, SQLPage will hide error messages and stack traces from the user, and will cache sql files in memory to avoid reloading them from disk. | +| `environment` | development | The environment in which SQLPage is running. Can be either `development` or `production`. Development HTML error reports include SQL source, request parameters, form values or request body, and request headers. Cookie and authorization headers are omitted. Uploaded files are identified by field, name, and size. Production error pages show a support reference you can look up in the server logs. Production also caches SQL files in memory to avoid reloading them from disk. | | `cache_stale_duration_ms` | 1000 (prod), 0 (dev) | The duration in milliseconds that a file can be cached before its freshness is checked against the filesystem. Defaults to 1000ms (1 second) in production and 0ms in development. | | `content_security_policy` | `script-src 'self' 'nonce-{NONCE}'` | The [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) to set in the HTTP headers. If you get CSP errors in the browser console, you can set this to the empty string to disable CSP. If you want a custom CSP that contains a nonce, include the `'nonce-{NONCE}'` directive in your configuration string and it will be populated with a random value per request. | | `smtp_host` | | SMTP server host used by the `sqlpage.send_mail` function. Set with `SMTP_HOST` in the environment. | diff --git a/examples/CRUD - Authentication/test.hurl b/examples/CRUD - Authentication/test.hurl index dd496aafc..842a8a9ec 100644 --- a/examples/CRUD - Authentication/test.hurl +++ b/examples/CRUD - Authentication/test.hurl @@ -4,7 +4,7 @@ HTTP 200 [Asserts] header "Content-Type" contains "text/html" body contains "Demo/Template CRUD with Authentication" -body not contains "An error occurred" +body not contains "data-sqlpage-error" # The currencies CRUD page is protected. GET http://localhost:8080/currencies_list.sql @@ -18,7 +18,7 @@ HTTP 200 body contains "Login" body contains "Username" body contains "Password" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/create_session.sql?path=/currencies_list.sql [FormParams] @@ -52,7 +52,7 @@ body contains "Currencies" body contains "New Record" body contains "RUR" body contains "USD" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/currencies_item_form.sql?id=1 HTTP 200 @@ -60,7 +60,7 @@ HTTP 200 body contains "Currency" body contains "Exchange Rate to RUR" body contains "RUR" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/currencies_item_form.sql?action=INSERT HTTP 200 @@ -68,7 +68,7 @@ HTTP 200 body contains "Currency" body contains "Exchange Rate to RUR" body contains "BROWSE" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/currencies_item_dml.sql?path=currencies_list.sql&action=UPDATE [FormParams] @@ -88,7 +88,7 @@ HTTP 200 body contains "HURLTEST" body contains "7.89" body htmlUnescape contains "currencies_item_form.sql?&path=/currencies_list.sql&id={{currency_id}}" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/currencies_item_dml.sql?path=currencies_list.sql&action=UPDATE [FormParams] @@ -106,7 +106,7 @@ HTTP 200 [Asserts] body contains "HURLEDITED" body contains "8.91" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/currencies_item_dml.sql?path=currencies_list.sql&action=DELETE [FormParams] @@ -122,7 +122,7 @@ GET http://localhost:8080/currencies_list.sql HTTP 200 [Asserts] body not contains "HURLEDITED" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/logout.sql?path=currencies_list.sql HTTP 302 diff --git a/examples/PostGIS - using sqlpage with geographic data/test.hurl b/examples/PostGIS - using sqlpage with geographic data/test.hurl index 3e9154e06..354a5406e 100644 --- a/examples/PostGIS - using sqlpage with geographic data/test.hurl +++ b/examples/PostGIS - using sqlpage with geographic data/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Points of interest" body contains "Add a point" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/add_point.sql [FormParams] @@ -31,7 +31,7 @@ paris_id: xpath "substring-after(string(//a[normalize-space(.)='Hurl Paris']/@hr body contains "Hurl Paris" body contains "Hurl Lyon" body htmlUnescape contains "point.sql?id={{paris_id}}" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/point.sql?id={{paris_id}} HTTP 200 @@ -42,7 +42,7 @@ body contains "First Hurl point" body contains "Closest points" body contains "Hurl Lyon" body htmlUnescape contains "edition_form.sql?id={{paris_id}}" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/edition_form.sql?id={{paris_id}} [FormParams] @@ -50,4 +50,4 @@ Text: Updated Hurl point HTTP 200 [Asserts] body contains "Updated Hurl point" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/SQLPage developer user interface/test.hurl b/examples/SQLPage developer user interface/test.hurl index 7784e7d75..3e4d0bfb3 100644 --- a/examples/SQLPage developer user interface/test.hurl +++ b/examples/SQLPage developer user interface/test.hurl @@ -7,7 +7,7 @@ body contains "Create new file" body contains "Database tables" body contains "sqlpage_files" body htmlUnescape contains "view_table.sql?table%5Fname=sqlpage%5Ffiles" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/edit.sql HTTP 200 @@ -15,7 +15,7 @@ HTTP 200 body contains "New page" body contains "insert_file.sql" body contains "code-editor" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/insert_file.sql [FormParams] @@ -29,7 +29,7 @@ GET http://localhost:8080/hurl_test.sql HTTP 200 [Asserts] body contains "Hello from Hurl" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/ HTTP 200 @@ -37,21 +37,21 @@ HTTP 200 body contains "hurl_test.sql" body htmlUnescape contains "edit.sql?path=hurl%5Ftest%2Esql" body htmlUnescape contains "delete.sql?path=hurl%5Ftest%2Esql" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/view_table.sql?table_name=sqlpage_files HTTP 200 [Asserts] body contains "sqlpage_files" body contains "hurl_test.sql" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/delete.sql?path=hurl_test.sql HTTP 200 [Asserts] body contains "Delete hurl_test.sql ?" body htmlUnescape contains "delete.sql?path=hurl%5Ftest%2Esql&confirm=yes" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/delete.sql?path=hurl_test.sql&confirm=yes HTTP 302 @@ -62,4 +62,4 @@ GET http://localhost:8080/ HTTP 200 [Asserts] body not contains "hurl_test.sql" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/cards-with-remote-content/test.hurl b/examples/cards-with-remote-content/test.hurl index 627dd514b..5c008ad7f 100644 --- a/examples/cards-with-remote-content/test.hurl +++ b/examples/cards-with-remote-content/test.hurl @@ -7,21 +7,21 @@ body contains "Markdown" body htmlUnescape contains "/chart-example.sql?_sqlpage_embed" body htmlUnescape contains "/map-example.sql?_sqlpage_embed" body htmlUnescape contains "/table-example.sql?_sqlpage_embed" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/chart-example.sql?_sqlpage_embed HTTP 200 [Asserts] xpath "normalize-space(//*[contains(., 'Quarterly Revenue')])" contains "Quarterly Revenue" body contains "2023-07-01T00:00:00Z" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/map-example.sql?_sqlpage_embed HTTP 200 [Asserts] body contains "New Delhi" body contains "28.6139" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/table-example.sql?_sqlpage_embed HTTP 200 @@ -29,4 +29,4 @@ HTTP 200 xpath "normalize-space(//*[contains(., 'Forename')])" contains "Forename" body contains "Ophir" body contains "Torvalds" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/corporate-conundrum/test.hurl b/examples/corporate-conundrum/test.hurl index 0e7063e2f..b1c170c9b 100644 --- a/examples/corporate-conundrum/test.hurl +++ b/examples/corporate-conundrum/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Welcome to Corporate Conundrum" body contains "Start a New Game" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/New%20Game.sql HTTP 302 @@ -18,7 +18,7 @@ HTTP 200 body contains "Players" body contains "Alice" body contains "Add a new player" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/next-question.sql?game_id={{game_id}}&player=Alice HTTP 302 @@ -33,13 +33,13 @@ HTTP 200 [Asserts] body contains "Submit your answer" body contains "Your answer" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/wait.sql?game_id={{game_id}}&question_id={{question_id}}&player=Alice&answer=42 HTTP 200 [Asserts] body contains "Waiting for other players to answer" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/next-question.sql?game_id={{game_id}}&player=Alice HTTP 302 @@ -52,4 +52,4 @@ HTTP 200 body contains "The game is over" body contains "Scores" body contains "Alice" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/custom form component/test.hurl b/examples/custom form component/test.hurl index 613b9f7af..ae8250705 100644 --- a/examples/custom form component/test.hurl +++ b/examples/custom form component/test.hurl @@ -5,7 +5,7 @@ body contains "Available Items" body contains "Selected Items" body contains "John Smith" body contains "Jane Doe" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/form_action.sql [FormParams] @@ -20,4 +20,4 @@ body contains "sarah@email.com" body contains "Lisa Anderson" body contains "lisa@email.com" body not contains "John Smith" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/forms with a variable number of fields/test.hurl b/examples/forms with a variable number of fields/test.hurl index e95b79152..5eefdbdba 100644 --- a/examples/forms with a variable number of fields/test.hurl +++ b/examples/forms with a variable number of fields/test.hurl @@ -5,7 +5,7 @@ body contains "Pass an order" body contains "Quantity of Invisible Umbrella" body contains "Quantity of Silent Alarm Clock" body contains "Quantity of Pet Rock 2.0" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/order_insert.sql [FormParams] @@ -31,4 +31,4 @@ body contains "1 x Silent Alarm Clock" body contains "Subtotal: 1 x 49.95" body contains "Total: 249.93 €" body not contains "Pet Rock 2.0" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/handle-404/test.hurl b/examples/handle-404/test.hurl index ecc430d37..9decfdfb2 100644 --- a/examples/handle-404/test.hurl +++ b/examples/handle-404/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Welcome to the API" body contains "Back home" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/api/does/not/actually/exist HTTP 200 @@ -11,4 +11,4 @@ HTTP 200 body htmlUnescape contains "\"serving_file\":\"api/404.sql\"" body htmlUnescape contains "\"request_path\":\"/api/does/not/actually/exist\"" body contains "Back home" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/image gallery with user uploads/test.hurl b/examples/image gallery with user uploads/test.hurl index a51609c68..9c0d80e61 100644 --- a/examples/image gallery with user uploads/test.hurl +++ b/examples/image gallery with user uploads/test.hurl @@ -5,7 +5,7 @@ HTTP 200 header "Content-Type" contains "text/html" body contains "My image gallery" body contains "Upload a new image" -body not contains "An error occurred" +body not contains "data-sqlpage-error" # Upload form is protected. GET http://localhost:8080/upload_form.sql @@ -19,7 +19,7 @@ HTTP 200 body contains "Login" body contains "Username" body contains "Password" -body not contains "An error occurred" +body not contains "data-sqlpage-error" # Demo credentials from the example migration: admin/admin. POST http://localhost:8080/create_session.sql @@ -39,7 +39,7 @@ body contains "Upload a new image" body contains "Title" body contains "Description" body contains "Image" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/upload.sql [Multipart] @@ -58,4 +58,4 @@ HTTP 200 body contains "Hurl test image" body contains "Uploaded by Hurl" body contains "/images/" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/light-dark-toggle/test.hurl b/examples/light-dark-toggle/test.hurl index c9265b0d2..1b4bfea62 100644 --- a/examples/light-dark-toggle/test.hurl +++ b/examples/light-dark-toggle/test.hurl @@ -4,7 +4,7 @@ HTTP 200 body contains "Toggle Light / Dark Mode" body contains "Categories" body contains "☀" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/toggle.sql Referer: http://localhost:8080/ @@ -19,7 +19,7 @@ HTTP 200 body contains "Biography" body contains "Morbi fermentum" body contains "data-bs-theme=\"dark\"" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/toggle.sql Referer: http://localhost:8080/biography.sql diff --git a/examples/make a geographic data application using sqlite extensions/test.hurl b/examples/make a geographic data application using sqlite extensions/test.hurl index 21f617f95..1da3c21f8 100644 --- a/examples/make a geographic data application using sqlite extensions/test.hurl +++ b/examples/make a geographic data application using sqlite extensions/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Points of interest" body contains "Add a point" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/add_point.sql [FormParams] @@ -31,7 +31,7 @@ paris_id: xpath "substring-after(string(//a[normalize-space(.)='Hurl Paris']/@hr body contains "Hurl Paris" body contains "Hurl Lyon" body htmlUnescape contains "point.sql?id={{paris_id}}" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/point.sql?id={{paris_id}} HTTP 200 @@ -41,4 +41,4 @@ body contains "2.3522" body contains "First Hurl point" body contains "Closest points" body contains "Hurl Lyon" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/master-detail-forms/test.hurl b/examples/master-detail-forms/test.hurl index 16312cbe1..ed01e0a3a 100644 --- a/examples/master-detail-forms/test.hurl +++ b/examples/master-detail-forms/test.hurl @@ -5,7 +5,7 @@ header "Content-Type" contains "text/html" body contains "SQLPage Form Demo" body contains "Users" body contains "Add a new user" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/insert_user.sql?id=987654 Content-Type: application/x-www-form-urlencoded @@ -23,7 +23,7 @@ body contains "Masterdetail" body contains "hurl-masterdetail@example.com" body contains "Addresses" body contains "Add address" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/insert_address.sql?user_id=987654 Content-Type: application/x-www-form-urlencoded @@ -38,7 +38,7 @@ HTTP 200 body contains "Hurl" body contains "Masterdetail" body contains "42 Hurl Street, Testville, Exampleland" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/insert_user.sql?id=987654 Content-Type: application/x-www-form-urlencoded @@ -55,11 +55,11 @@ body contains "Updated" body contains "hurl-updated-masterdetail@example.com" body contains "42 Hurl Street, Testville, Exampleland" body not contains "Masterdetail" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080 HTTP 200 [Asserts] body contains "Hurl Updated" body contains "hurl-updated-masterdetail@example.com" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/microsoft sql server advanced forms/test.hurl b/examples/microsoft sql server advanced forms/test.hurl index 90678921b..832d43b75 100644 --- a/examples/microsoft sql server advanced forms/test.hurl +++ b/examples/microsoft sql server advanced forms/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] xpath "//form//input[@name='Name']" exists xpath "//form//input[@name='GroupDescription']" exists -xpath "//code[@class='sqlpage-error-description']" not exists +xpath "//article[@data-sqlpage-error]" not exists # The form maps a blank description to SQL NULL before binding the insert. POST http://127.0.0.1:8080/ @@ -14,7 +14,7 @@ HTTP 200 [Captures] unicode_group_id: xpath "string(//select[@name='Memberships[]'][@multiple]/option[normalize-space(.)=\"L'équipe 東京\"]/@value)" [Asserts] -xpath "//code[@class='sqlpage-error-description']" not exists +xpath "//article[@data-sqlpage-error]" not exists variable "unicode_group_id" matches "^[0-9]+$" xpath "string(//div[contains(@class, 'alert-success')][.//h4='Group created']//div[@class='alert-description'])" == "L'équipe 東京" xpath "//div[contains(@class, 'alert-success')][.//h4='Group created']//a[@href='#group-{{unicode_group_id}}']" exists @@ -35,7 +35,7 @@ Name: Rejected group GroupDescription: This description is more than eighty characters long and exceeds the database column size. HTTP 200 [Asserts] -xpath "string(//code[@class='sqlpage-error-description'])" contains "would be truncated" +xpath "string(//article[@data-sqlpage-error]/h2)" contains "would be truncated" xpath "//div[contains(@class, 'alert-success')][.//h4='Group created']" not exists POST http://127.0.0.1:8080/ @@ -46,7 +46,7 @@ HTTP 200 [Captures] recovered_group_id: xpath "string(//select[@name='Memberships[]'][@multiple]/option[normalize-space(.)='Recovered group']/@value)" [Asserts] -xpath "//code[@class='sqlpage-error-description']" not exists +xpath "//article[@data-sqlpage-error]" not exists xpath "//select[@name='Memberships[]'][@multiple]/option[@value='{{unicode_group_id}}']" exists variable "recovered_group_id" matches "^[0-9]+$" @@ -65,7 +65,7 @@ Content-Type: application/x-www-form-urlencoded `UserName=Report+Reader&Memberships%5B%5D={{unicode_group_id}}&Memberships%5B%5D=-1` HTTP 200 [Asserts] -xpath "string(//code[@class='sqlpage-error-description'])" contains "FK_group_members_groups" +xpath "string(//article[@data-sqlpage-error]/h2)" contains "FK_group_members_groups" GET http://127.0.0.1:8080/ Accept: application/json @@ -80,14 +80,14 @@ Content-Type: application/x-www-form-urlencoded `UserName=Report+Reader&Memberships%5B%5D={{unicode_group_id}}&Memberships%5B%5D={{recovered_group_id}}` HTTP 200 [Asserts] -xpath "//code[@class='sqlpage-error-description']" not exists +xpath "//article[@data-sqlpage-error]" not exists POST http://127.0.0.1:8080/ [FormParams] UserName: Élodie HTTP 200 [Asserts] -xpath "//code[@class='sqlpage-error-description']" not exists +xpath "//article[@data-sqlpage-error]" not exists xpath "//p[normalize-space()='No groups assigned']" exists GET http://127.0.0.1:8080/ diff --git a/examples/modeling a many to many relationship with a form/test.hurl b/examples/modeling a many to many relationship with a form/test.hurl index 16795658d..7c95c1d72 100644 --- a/examples/modeling a many to many relationship with a form/test.hurl +++ b/examples/modeling a many to many relationship with a form/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Recent blog posts" body contains "Write a post !" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/write.sql HTTP 200 @@ -12,7 +12,7 @@ body contains "Title of the post" body contains "Main Topic" body contains "Technology" body contains "Travel" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/write_submit.sql Content-Type: application/x-www-form-urlencoded @@ -30,4 +30,4 @@ body contains "Hurl content for the many-to-many form." body contains "Technology" body contains "Travel" body contains "Food" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/multiple-choice-question/test.hurl b/examples/multiple-choice-question/test.hurl index 70d20bce3..ce40a0e6e 100644 --- a/examples/multiple-choice-question/test.hurl +++ b/examples/multiple-choice-question/test.hurl @@ -6,7 +6,7 @@ body contains "What dog lover are you ?" body contains "process.sql" body contains "I love dogs" body contains "I hate them" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/process.sql [FormParams] @@ -21,4 +21,4 @@ HTTP 200 header "Content-Type" contains "text/html" body contains "I love dogs" body contains "100" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/mysql json handling/test.hurl b/examples/mysql json handling/test.hurl index 77ebbaf0a..16fb5207b 100644 --- a/examples/mysql json handling/test.hurl +++ b/examples/mysql json handling/test.hurl @@ -4,7 +4,7 @@ HTTP 200 header "Content-Type" contains "text/html" xpath "//html" exists xpath "//body" exists -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/ Content-Type: application/x-www-form-urlencoded @@ -13,7 +13,7 @@ Name: Hurl Analysts HTTP 200 [Asserts] body contains "Hurl Analysts" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/ Content-Type: application/x-www-form-urlencoded @@ -25,7 +25,7 @@ analysts_id: xpath "string(//select[@name='Memberships[]']/option[normalize-spac reviewers_id: xpath "string(//select[@name='Memberships[]']/option[normalize-space(.)='Hurl Reviewers']/@value)" [Asserts] body contains "Hurl Reviewers" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/ Content-Type: application/x-www-form-urlencoded @@ -34,4 +34,4 @@ HTTP 200 [Asserts] body contains "Hurl User" body htmlUnescape contains "Hurl Analysts,Hurl Reviewers" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/official-site/test.hurl b/examples/official-site/test.hurl index 78af88820..b0e8f1f51 100644 --- a/examples/official-site/test.hurl +++ b/examples/official-site/test.hurl @@ -9,7 +9,7 @@ body contains "Override any component." body contains "Copy files. Or don't." xpath "string(//button[@id='instant-tab']/@aria-selected)" == "true" body contains "/assets/landing/js/main.js" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/documentation.sql HTTP 200 @@ -17,20 +17,20 @@ HTTP 200 body contains "SQLPage v" xpath "string(//main//a[normalize-space()='Components']/@href)" == "/components.sql" xpath "string(//main//a[normalize-space()='Functions']/@href)" == "/functions.sql" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/components.sql HTTP 200 [Asserts] xpath "string(//main//h3/a[span='shell']/@href)" == "/component.sql?component=shell" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/component.sql?component=form HTTP 200 [Asserts] body contains "The form component" body contains "Building forms in SQL" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/component.sql?component=alert HTTP 200 @@ -75,7 +75,7 @@ HTTP 200 [Asserts] body contains "sqlpage.url_encode" body contains "Parameters" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/llms.txt HTTP 200 @@ -120,7 +120,7 @@ GET http://localhost:8080/search.sql?search=migrations HTTP 200 [Asserts] xpath "//main//a[@href='/your-first-sql-website/migrations.sql']" count == 1 -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/your-first-sql-website/ User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) @@ -160,13 +160,13 @@ HTTP 200 [Asserts] body contains "Developer UI" body not contains "Roundest Pokemon" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/not-a-real-doc-page HTTP 404 [Asserts] body contains "Not Found" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/examples/authentication/ HTTP 302 @@ -178,7 +178,7 @@ HTTP 200 [Asserts] body contains "Demo Login Form" body contains "admin" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/examples/authentication/create_session_token.sql [FormParams] @@ -193,7 +193,7 @@ HTTP 200 [Asserts] body contains "You are logged in as admin" body contains "Log out" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/examples/authentication/logout.sql HTTP 302 @@ -205,14 +205,14 @@ HTTP 200 [Asserts] body contains "Acme Corp" body contains "data-pre-init=\"table\"" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/landing-demos/demo.sql?component=chart HTTP 200 [Asserts] body contains "Tickets resolved" body contains "2026-09-30" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/landing-demos/save.sql [FormParams] @@ -223,7 +223,7 @@ HTTP 200 body contains "Hello, Ada!" body contains "Query crew" body contains "This preview is private to your submission." -body not contains "An error occurred" +body not contains "data-sqlpage-error" # A fresh visitor always sees the seeded profile, never another submission. GET http://localhost:8080/landing-demos/demo.sql?component=form @@ -236,7 +236,7 @@ GET http://localhost:8080/landing-demos/demo.sql?component=big_number HTTP 200 [Asserts] body contains "98%" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/landing-demos/source.sql?component=../../configuration HTTP 200 @@ -255,7 +255,7 @@ HTTP 200 [Asserts] body contains "component-catalog" xpath "string(//a[span='form']/@href)" == "/component.sql?component=form" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/landing-demos/save.sql [FormParams] diff --git a/examples/official-site/your-first-sql-website/tutorial.md b/examples/official-site/your-first-sql-website/tutorial.md index 7ef99a11e..1f21b1728 100644 --- a/examples/official-site/your-first-sql-website/tutorial.md +++ b/examples/official-site/your-first-sql-website/tutorial.md @@ -30,6 +30,8 @@ In this case, we use the [`list` component](/component.sql?component=list) to di The second line defines the data that will populate the component. All the components you can use and their properties are documented in [SQLPage's online documentation](/components.sql). +If a SQL file fails, the development error page shows the diagnostic and the available source location. Use the copy icon to copy a report with the SQL, request data, and database details. On a production site, visitors see a support reference you can search for in the server logs. + ## Your database schema > If you already have a database populated with data, diff --git a/examples/plots tables and forms/test.hurl b/examples/plots tables and forms/test.hurl index 8112344d0..9a19d7921 100644 --- a/examples/plots tables and forms/test.hurl +++ b/examples/plots tables and forms/test.hurl @@ -10,7 +10,7 @@ body contains "Jane" body contains "1 times 1" body contains "10 times 10" body contains "New User" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/?x=3 @@ -19,7 +19,7 @@ HTTP 200 body contains "1 times 3" body contains "10 times 3" body contains "New User" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/ Content-Type: application/x-www-form-urlencoded @@ -32,4 +32,4 @@ HTTP 200 body contains "Ada" body contains "1" body contains "2" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/read-and-set-http-cookies/test.hurl b/examples/read-and-set-http-cookies/test.hurl index ec197e359..c2bce4958 100644 --- a/examples/read-and-set-http-cookies/test.hurl +++ b/examples/read-and-set-http-cookies/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "User Name" body contains "View the cookie from a subdirectory" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/ [FormParams] @@ -12,23 +12,23 @@ HTTP 200 [Asserts] header "Set-Cookie" contains "username=Hurl%20Cookie" body contains "Hurl Cookie" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/ HTTP 200 [Asserts] body contains "Hurl Cookie" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/subdirectory/read_cookies.sql HTTP 200 [Asserts] body contains "The value of your username cookie was: Hurl Cookie" body contains "It has now been removed" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/ HTTP 200 [Asserts] body not contains "Hurl Cookie" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/rich-text-editor/test.hurl b/examples/rich-text-editor/test.hurl index 29c64bcde..0bf5b6748 100644 --- a/examples/rich-text-editor/test.hurl +++ b/examples/rich-text-editor/test.hurl @@ -4,7 +4,7 @@ HTTP 200 body contains "Rich text editor" body contains "Create a new blog post" body contains "Blog posts" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/create_blog_post [FormParams] @@ -23,7 +23,7 @@ body contains "Hurl Rich Post" body contains "Hurl" body contains "rich" body contains "Edit" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/edit?id=1 [FormParams] @@ -38,4 +38,4 @@ HTTP 200 [Asserts] body contains "Hurl Updated Post" body contains "Updated rich content" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/simple-website-example/test.hurl b/examples/simple-website-example/test.hurl index 22e87e8fb..21296558e 100644 --- a/examples/simple-website-example/test.hurl +++ b/examples/simple-website-example/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Add a user" body contains "Users" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/ [FormParams] @@ -12,7 +12,7 @@ HTTP 200 [Asserts] body contains "Hurl User" body contains "user.sql?id" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/user.sql?id=1 HTTP 200 @@ -20,7 +20,7 @@ HTTP 200 body contains "Hurl User" body contains "Edit user" body contains "Delete this user" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/edit.sql?id=1 [FormParams] @@ -30,18 +30,18 @@ HTTP 200 [Asserts] body contains "Hurl Admin" body contains "Has administrator privileges" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/ HTTP 200 [Asserts] body contains "Hurl Admin" body not contains "Hurl User is a user" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/delete.sql?id=1 HTTP 200 [Asserts] body contains "The user Hurl Admin has been deleted." body contains "Back to the user list" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/single sign on/test.hurl b/examples/single sign on/test.hurl index e2ed4e848..07de20488 100644 --- a/examples/single sign on/test.hurl +++ b/examples/single sign on/test.hurl @@ -5,7 +5,7 @@ header "Content-Type" contains "text/html" body contains "Welcome" body contains "Log in" body htmlUnescape contains "/protected" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/protected HTTP 303 @@ -47,4 +47,4 @@ body htmlUnescape contains "You're in, John Smith" body contains "demo@example.com" body contains "You have access to this protected page." body htmlUnescape contains "/assets/welcome.jpeg" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/telemetry/test.hurl b/examples/telemetry/test.hurl index f03b69a1b..b183b5aff 100644 --- a/examples/telemetry/test.hurl +++ b/examples/telemetry/test.hurl @@ -4,7 +4,7 @@ HTTP 200 [Asserts] body contains "Todo List" body contains "Add a todo" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/add_todo.sql traceparent: 00-00000000000000000000000000000002-0000000000000002-01 @@ -19,7 +19,7 @@ traceparent: 00-00000000000000000000000000000003-0000000000000003-01 HTTP 200 [Asserts] body contains "Hurl telemetry todo" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:3200/api/search?q=%7Bresource.service.name%3D%22sqlpage%22%7D&limit=20 [Options] diff --git a/examples/tiny_twitter/test.hurl b/examples/tiny_twitter/test.hurl index e01769276..846279bc5 100644 --- a/examples/tiny_twitter/test.hurl +++ b/examples/tiny_twitter/test.hurl @@ -4,7 +4,7 @@ HTTP 200 body contains "TinyTweeter" body contains "Tell me your story..." body contains "Terms and conditions" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080 [FormParams] @@ -13,4 +13,4 @@ HTTP 200 [Asserts] body contains "TinyTweeter" body contains "Hurl tiny twitter post" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/todo application (PostgreSQL)/test.hurl b/examples/todo application (PostgreSQL)/test.hurl index 52e4c08df..630ed0881 100644 --- a/examples/todo application (PostgreSQL)/test.hurl +++ b/examples/todo application (PostgreSQL)/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "Todo" body contains "Add new todo" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/todo_form.sql [FormParams] @@ -20,7 +20,7 @@ todo_id: xpath "substring-after(string((//a[contains(@href, 'todo_form.sql?todo_ body contains "Created by Hurl" body htmlUnescape contains "todo_form.sql?todo_id={{todo_id}}" body htmlUnescape contains "delete.sql?todo_id={{todo_id}}" -body not contains "An error occurred" +body not contains "data-sqlpage-error" POST http://localhost:8080/todo_form.sql?todo_id={{todo_id}} [FormParams] @@ -35,7 +35,7 @@ HTTP 200 body contains "Confirm deletion" body contains "Edited by Hurl" body htmlUnescape contains "?todo_id={{todo_id}}&confirm=yes" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/delete.sql?todo_id={{todo_id}}&confirm=yes HTTP 302 @@ -46,4 +46,4 @@ GET http://localhost:8080/ HTTP 200 [Asserts] body not contains "Edited by Hurl" -body not contains "An error occurred" +body not contains "data-sqlpage-error" diff --git a/examples/user-authentication/test.hurl b/examples/user-authentication/test.hurl index d5460181c..7049ae01b 100644 --- a/examples/user-authentication/test.hurl +++ b/examples/user-authentication/test.hurl @@ -3,7 +3,7 @@ HTTP 200 [Asserts] body contains "SQLPage Authentication Demo" body contains "Access protected page" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/signin.sql HTTP 200 @@ -46,7 +46,7 @@ HTTP 200 [Asserts] body contains "Welcome, hurl_user" body contains "top secret" -body not contains "An error occurred" +body not contains "data-sqlpage-error" GET http://localhost:8080/logout.sql HTTP 302 diff --git a/frontend/src/error-report.ts b/frontend/src/error-report.ts new file mode 100644 index 000000000..1e7c6cab2 --- /dev/null +++ b/frontend/src/error-report.ts @@ -0,0 +1,36 @@ +// Event delegation also handles errors appended to a streamed or embedded page. +document.addEventListener("click", async (event) => { + const button = + event.target instanceof Element && + event.target.closest("button[data-copy-error]"); + if (!button) return; + const card = button.closest("[data-sqlpage-error]"); + const report = card?.querySelector( + "template[data-error-report]", + ); + const status = card?.querySelector("[role=status]"); + if (!report || !status) return; + const text = report.content.textContent ?? ""; + try { + await navigator.clipboard.writeText(text); + status.textContent = "Copied"; + } catch { + // HTTP development servers may have only the synchronous clipboard API. + let copied = false; + const onCopy = (e: ClipboardEvent) => { + if (!e.clipboardData) return; + e.clipboardData.setData("text/plain", text); + e.preventDefault(); + copied = true; + }; + document.addEventListener("copy", onCopy); + try { + document.execCommand("copy"); + } catch { + copied = false; + } finally { + document.removeEventListener("copy", onCopy); + status.textContent = copied ? "Copied" : "Clipboard unavailable"; + } + } +}); diff --git a/frontend/src/sqlpage.ts b/frontend/src/sqlpage.ts index e616f050b..464953bb5 100644 --- a/frontend/src/sqlpage.ts +++ b/frontend/src/sqlpage.ts @@ -1,3 +1,4 @@ +import "./error-report"; import { bootstrap as bundled_bootstrap } from "@tabler/core"; import type * as Leaflet from "leaflet"; import { add_init_fn, type InitRoot, select_all } from "./init.ts"; diff --git a/sqlpage/templates/error.handlebars b/sqlpage/templates/error.handlebars index a78e5560a..ef4fb75ec 100644 --- a/sqlpage/templates/error.handlebars +++ b/sqlpage/templates/error.handlebars @@ -1,34 +1,79 @@ {{!-- Display a page or query error. ---}}