Skip to content

Commit

Permalink
[processing] Better error reporting when features fail to be added to…
Browse files Browse the repository at this point in the history
… 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 c912564
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -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.