Skip to content

Commit d797a9b

Browse files
committed
Fix some processing algorithm exception handling
1 parent 144d733 commit d797a9b

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/core/processing/qgsnativealgorithms.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,24 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap
918918

919919
if ( fieldType != QVariant::String && ( op == BeginsWith || op == Contains || op == DoesNotContain ) )
920920
{
921-
#if 0
922-
op = ''.join( ['"%s", ' % o for o in self.STRING_OPERATORS] )
923-
raise GeoAlgorithmExecutionException(
924-
self.tr( 'Operators {0} can be used only with string fields.' ).format( op ) )
925-
#endif
926-
return QVariantMap();
921+
QString method;
922+
switch ( op )
923+
{
924+
case BeginsWith:
925+
method = QObject::tr( "begins with" );
926+
break;
927+
case Contains:
928+
method = QObject::tr( "contains" );
929+
break;
930+
case DoesNotContain:
931+
method = QObject::tr( "does not contain" );
932+
break;
933+
934+
default:
935+
break;
936+
}
937+
938+
throw QgsProcessingException( QObject::tr( "Operator '%1' can be used only with string fields." ).arg( method ) );
927939
}
928940

929941
QString fieldRef = QgsExpression::quotedColumnRef( fieldName );
@@ -969,8 +981,7 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap
969981
QgsExpression expression( expr );
970982
if ( expression.hasParserError() )
971983
{
972-
// raise GeoAlgorithmExecutionException(expression.parserErrorString())
973-
return QVariantMap();
984+
throw QgsProcessingException( expression.parserErrorString() );
974985
}
975986

976987
QgsExpressionContext expressionContext = createExpressionContext( parameters, context );

src/core/processing/qgsprocessingalgrunnertask.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,15 @@ bool QgsProcessingAlgRunnerTask::run()
4040
{
4141
connect( mFeedback.get(), &QgsFeedback::progressChanged, this, &QgsProcessingAlgRunnerTask::setProgress );
4242
bool ok = false;
43-
mResults = mAlgorithm->run( mParameters, mContext, mFeedback.get(), &ok );
44-
return ok && !mFeedback->isCanceled();
43+
try
44+
{
45+
mResults = mAlgorithm->run( mParameters, mContext, mFeedback.get(), &ok );
46+
}
47+
catch ( QgsProcessingException & )
48+
{
49+
return false;
50+
}
51+
return !mFeedback->isCanceled();
4552
}
4653

4754
void QgsProcessingAlgRunnerTask::finished( bool result )

0 commit comments

Comments
 (0)