Skip to content

Commit 27714fc

Browse files
committedApr 30, 2018
[expression] Show expected arg count if wrong args passed
1 parent dcde8ee commit 27714fc

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed
 

‎src/core/qgsexpressionparser.yy

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,26 @@ expression:
224224
delete $3;
225225
YYERROR;
226226
}
227-
if ( QgsExpression::Functions()[fnIndex]->params() != -1
228-
&& !( QgsExpression::Functions()[fnIndex]->params() >= $3->count()
229-
&& QgsExpression::Functions()[fnIndex]->minParams() <= $3->count() ) )
227+
QgsExpressionFunction* func = QgsExpression::Functions()[fnIndex];
228+
if ( func->params() != -1
229+
&& !( func->params() >= $3->count()
230+
&& func->minParams() <= $3->count() ) )
230231
{
231232
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
232233
parser_ctx->currentErrorType = errorType;
233-
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
234+
QString expectedMessage;
235+
if (func->params() == func->minParams())
236+
{
237+
expectedMessage = QString("Expected %2" ).arg( func->params());
238+
}
239+
else
240+
{
241+
expectedMessage = QString("Expected between %2 and %4 max but got %3" ).arg( func->minParams(), func->params() );
Code has comments. Press enter to view.
242+
}
243+
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments."
244+
"%2 but got %3" ).arg( QgsExpression::Functions()[fnIndex]->name() )
245+
.arg( expectedMessage )
246+
.arg( $3->count() ).toLocal8Bit().constData() );
234247
delete $3;
235248
YYERROR;
236249
}

0 commit comments

Comments
 (0)
Please sign in to comment.