Skip to content

Commit

Permalink
Fix expression parser error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 19, 2018
1 parent 30b55cc commit 06354ef
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/core/qgsexpressionparser.yy
Expand Up @@ -239,21 +239,19 @@ expression:
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs; QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
parser_ctx->currentErrorType = errorType; parser_ctx->currentErrorType = errorType;
QString expectedMessage; QString expectedMessage;
if (func->params() == func->minParams()) if ( func->params() == func->minParams() )
{ {
expectedMessage = QString("Expected %2" ).arg( func->params()); expectedMessage = QStringLiteral( "Expected %1 but got %2." ).arg( QString::number( func->params() ), QString::number( $3->count() ) );
} }
else else
{ {
expectedMessage = QString("Expected between %2 and %4 max but got %3" ).arg( func->minParams(), func->params() ); expectedMessage = QStringLiteral( "Expected between %1 and %2 parameters but %3 were provided." ).arg( QString::number( func->minParams() ), QString::number( func->params() ), QString::number( $3->count() ) );
} }
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments." exp_error(&yyloc, parser_ctx, QStringLiteral( "%1 function is called with wrong number of arguments. %2" ).arg( QgsExpression::Functions()[fnIndex]->name(), expectedMessage ).toUtf8().constData() );
"%2 but got %3" ).arg( QgsExpression::Functions()[fnIndex]->name() )
.arg( expectedMessage )
.arg( $3->count() ).toLocal8Bit().constData() );
delete $3; delete $3;
YYERROR; YYERROR;
} }

$$ = new QgsExpressionNodeFunction(fnIndex, $3); $$ = new QgsExpressionNodeFunction(fnIndex, $3);
addParserLocation(&@1, $$); addParserLocation(&@1, $$);
} }
Expand Down

0 comments on commit 06354ef

Please sign in to comment.