Skip to content

Commit

Permalink
Fix some processing algorithm exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 28, 2017
1 parent 144d733 commit d797a9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/core/processing/qgsnativealgorithms.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
11 changes: 9 additions & 2 deletions src/core/processing/qgsprocessingalgrunnertask.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit d797a9b

Please sign in to comment.