Skip to content

Commit 17e6e1e

Browse files
authored
Improve SQLPage function argument warnings (#1225)
* improve sqlpage function argument warnings with source context Made-with: Cursor * Param extraction: Result-based errors, single caller message, no CompoundIdentifier special case - expr_to_stmt_param returns Result<StmtParam, ExprToParamError>; error carries only line + kind (UnsupportedExpr, UnemulatedFunction, NamedArgs) - function_args_to_stmt_params logs one formatted message (ctx.format_param_error) then returns Err - Single unsupported-expr arm; expr_summary() used for description - Rename ParamWarnContext to ParamExtractContext Made-with: Cursor * Surface param extraction error in parse result; add parse_sql error-message tests; remove are_params_extractable - When func_call_to_param returns StmtParam::Error, store it and have extract_parameters return Err so parse yields ParsedStatement::Error with specialized message - Add test_parse_sql_unsupported_expr_in_sqlpage_arg and test_parse_sql_unemulated_function_in_sqlpage_arg - Remove dead are_params_extractable and its unused import Made-with: Cursor * Refactor sqlpage function argument error messages to match user expectations - Overhauled ExprToParamError formatting to construct exact user-friendly descriptions. - Removed superfluous anyhow::Context prefixes in func_call_to_param. - Passed source_path properly through validate_function_calls to ensure file line numbers populate the new error template accurately. - Renamed error test file to match its dynamic error output signature. - Removed redundant mut mutability warnings on parsing logic loops. * improve error messages * Refactor SqlPageFunctionError representation to clean up 'syntax error' wrappers - Replaced stringly-typed anyhow errors with a strongly typed SqlPageFunctionError. - Removed source_path threading completely from the parameter extraction phases, conforming to better separation of concerns. - Appended file path prefix dynamically at the evaluation stage in clone_anyhow_err strictly when downcasting to SqlPageFunctionError. - Removed the confusing generic 'Caused by: x.sql contains a syntax error...' wrapper from actual function logic errors. * Remove redundant 'reorganize' hint from error message * readd deleted test * split parameter extraction logic into a separate file * Add to changelog
1 parent cc8848f commit 17e6e1e

File tree

7 files changed

+688
-504
lines changed

7 files changed

+688
-504
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- OIDC protected and public paths now respect the site prefix when it is defined.
55
- Fix: forms without submit or reset buttons no longer keep extra bottom spacing.
66
- add submit and reset form button icons: validate_icon, reset_icon, reset_color
7+
- improve error messages when sqlpage functions are used incorrectly. Include precise file reference and line number
78

89
## 0.42.0 (2026-01-17)
910

src/webserver/database/execute_queries.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ fn debug_row(r: &AnyRow) {
331331
}
332332

333333
fn clone_anyhow_err(source_file: &Path, err: &anyhow::Error) -> anyhow::Error {
334+
if let Some(func_err) = err.downcast_ref::<super::sql::SqlPageFunctionError>() {
335+
let line = func_err.line;
336+
let loc = if line > 0 {
337+
format!(":{line}")
338+
} else {
339+
String::new()
340+
};
341+
return anyhow::anyhow!("{}{loc} {}", source_file.display(), func_err);
342+
}
343+
334344
let mut e = anyhow!("{} contains a syntax error preventing SQLPage from parsing and preparing its SQL statements.", source_file.display());
335345
for c in err.chain().rev() {
336346
e = e.context(c.to_string());

0 commit comments

Comments
 (0)