Skip to content
Permalink
Browse files

Fix some processing algorithm exception handling

  • Loading branch information
nyalldawson committed Jun 28, 2017
1 parent 144d733 commit d797a9b3cff34160dfa243f9dab0a8053450c5af
Showing with 28 additions and 10 deletions.
  1. +19 −8 src/core/processing/qgsnativealgorithms.cpp
  2. +9 −2 src/core/processing/qgsprocessingalgrunnertask.cpp
@@ -918,12 +918,24 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap

if ( fieldType != QVariant::String && ( op == BeginsWith || op == Contains || op == DoesNotContain ) )
{
#if 0
op = ''.join( ['"%s", ' % o for o in self.STRING_OPERATORS] )
raise GeoAlgorithmExecutionException(
self.tr( 'Operators {0} can be used only with string fields.' ).format( op ) )
#endif
return QVariantMap();
QString method;
switch ( op )
{
case BeginsWith:
method = QObject::tr( "begins with" );
break;
case Contains:
method = QObject::tr( "contains" );
break;
case DoesNotContain:
method = QObject::tr( "does not contain" );
break;

default:
break;
}

throw QgsProcessingException( QObject::tr( "Operator '%1' can be used only with string fields." ).arg( method ) );
}

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

QgsExpressionContext expressionContext = createExpressionContext( parameters, context );
@@ -40,8 +40,15 @@ bool QgsProcessingAlgRunnerTask::run()
{
connect( mFeedback.get(), &QgsFeedback::progressChanged, this, &QgsProcessingAlgRunnerTask::setProgress );
bool ok = false;
mResults = mAlgorithm->run( mParameters, mContext, mFeedback.get(), &ok );
return ok && !mFeedback->isCanceled();
try
{
mResults = mAlgorithm->run( mParameters, mContext, mFeedback.get(), &ok );
}
catch ( QgsProcessingException & )
{
return false;
}
return !mFeedback->isCanceled();
}

void QgsProcessingAlgRunnerTask::finished( bool result )

0 comments on commit d797a9b

Please sign in to comment.
You can’t perform that action at this time.