Skip to content
Permalink
Browse files

[processing] Better error reporting when features fail to be added to…

… an output

Use a descriptive error message which explains why the feature addition failed,
instead of a generic error message
  • Loading branch information
nyalldawson committed Jul 22, 2020
1 parent 3eec9a4 commit c912564452ed69fb702b28dda2738defc706bb41
Showing with 21 additions and 3 deletions.
  1. +21 −3 src/core/processing/qgsprocessingutils.cpp
@@ -1383,22 +1383,40 @@ bool QgsProcessingFeatureSink::addFeature( QgsFeature &feature, QgsFeatureSink::
{
bool result = QgsProxyFeatureSink::addFeature( feature, flags );
if ( !result && mContext.feedback() )
mContext.feedback()->reportError( QObject::tr( "Feature could not be written to %1" ).arg( mSinkName ) );
{
const QString error = lastError();
if ( !error.isEmpty() )
mContext.feedback()->reportError( QObject::tr( "Feature could not be written to %1: %2" ).arg( mSinkName, error ) );
else
mContext.feedback()->reportError( QObject::tr( "Feature could not be written to %1" ).arg( mSinkName ) );
}
return result;
}

bool QgsProcessingFeatureSink::addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags )
{
bool result = QgsProxyFeatureSink::addFeatures( features, flags );
if ( !result && mContext.feedback() )
mContext.feedback()->reportError( QObject::tr( "%1 feature(s) could not be written to %2" ).arg( features.count() ).arg( mSinkName ) );
{
const QString error = lastError();
if ( !error.isEmpty() )
mContext.feedback()->reportError( QObject::tr( "%1 feature(s) could not be written to %2: %3" ).arg( features.count() ).arg( mSinkName, error ) );
else
mContext.feedback()->reportError( QObject::tr( "%1 feature(s) could not be written to %2" ).arg( features.count() ).arg( mSinkName ) );
}
return result;
}

bool QgsProcessingFeatureSink::addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags )
{
bool result = QgsProxyFeatureSink::addFeatures( iterator, flags );
if ( !result && mContext.feedback() )
mContext.feedback()->reportError( QObject::tr( "Features could not be written to %1" ).arg( mSinkName ) );
{
const QString error = lastError();
if ( !error.isEmpty() )
mContext.feedback()->reportError( QObject::tr( "Features could not be written to %1: %2" ).arg( mSinkName, error ) );
else
mContext.feedback()->reportError( QObject::tr( "Features could not be written to %1" ).arg( mSinkName ) );
}
return result;
}

0 comments on commit c912564

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