Skip to content

Commit 7a716e5

Browse files
committed
fix: improve error message for unsupported sqlpage function arguments
Update expr_to_stmt_param to correctly bubble up UnsupportedExpr errors with the summary of the larger compound expression. This ensures the error message shows the full expression (like 'x || c') instead of just the inner leaf node ('x').
1 parent 003f3e0 commit 7a716e5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/webserver/database/sql/parameter_extraction.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn expr_to_stmt_param(
379379
ctx: &ParamExtractContext,
380380
) -> Result<StmtParam, ExprToParamError> {
381381
let line = arg.span().start.line;
382-
match arg {
382+
let res = match arg {
383383
Expr::Value(ValueWithSpan {
384384
value: Value::Placeholder(placeholder),
385385
..
@@ -419,11 +419,8 @@ fn expr_to_stmt_param(
419419
left,
420420
op: BinaryOperator::StringConcat,
421421
right,
422-
} => {
423-
let left = expr_to_stmt_param(left, ctx)?;
424-
let right = expr_to_stmt_param(right, ctx)?;
425-
Ok(StmtParam::Concat(vec![left, right]))
426-
}
422+
} => expr_to_stmt_param(left, ctx)
423+
.and_then(|l| expr_to_stmt_param(right, ctx).map(|r| StmtParam::Concat(vec![l, r]))),
427424
Expr::Function(Function {
428425
name: ObjectName(func_name_parts),
429426
args:
@@ -446,7 +443,16 @@ fn expr_to_stmt_param(
446443
summary: expr_summary(arg),
447444
},
448445
}),
449-
}
446+
};
447+
448+
res.map_err(|mut e| {
449+
if let ExprToParamErrorKind::UnsupportedExpr { ref mut summary } = e.kind {
450+
if !matches!(arg, Expr::Function(_)) {
451+
*summary = expr_summary(arg);
452+
}
453+
}
454+
e
455+
})
450456
}
451457

452458
fn function_arg_expr(arg: &mut FunctionArg) -> Option<&mut Expr> {

0 commit comments

Comments
 (0)