Skip to content

Commit

Permalink
Better reporting for invalid field names for some algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 18, 2024
1 parent 5b912fa commit d95ac4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion python/plugins/processing/algs/qgis/BasicStatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ def processAlgorithm(self, parameters, context, feedback):
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT_LAYER))

field_name = self.parameterAsString(parameters, self.FIELD_NAME, context)
field = source.fields().at(source.fields().lookupField(field_name))
field_idx = source.fields().lookupField(field_name)
if field_idx < 0:
raise QgsProcessingException(self.tr("Invalid field for statistics: “{}” does not exist").format(field_name))

field = source.fields().at(field_idx)

output_file = self.parameterAsFileOutput(parameters, self.OUTPUT_HTML_FILE, context)

Expand Down
7 changes: 5 additions & 2 deletions src/analysis/processing/qgsalgorithmjoinbyattribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ QVariantMap QgsJoinByAttributeAlgorithm::processAlgorithm( const QVariantMap &pa
const QStringList fieldsToCopy = parameterAsStrings( parameters, QStringLiteral( "FIELDS_TO_COPY" ), context );

const int joinField1Index = input->fields().lookupField( field1Name );
if ( joinField1Index < 0 )
throw QgsProcessingException( QObject::tr( "Invalid join field from layer 1: “%1” does not exist" ).arg( field1Name ) );

const int joinField2Index = input2->fields().lookupField( field2Name );
if ( joinField1Index < 0 || joinField2Index < 0 )
throw QgsProcessingException( QObject::tr( "Invalid join fields" ) );
if ( joinField2Index < 0 )
throw QgsProcessingException( QObject::tr( "Invalid join field from layer 2: “%1” does not exist" ).arg( field2Name ) );

QgsFields outFields2;
QgsAttributeList fields2Indices;
Expand Down

0 comments on commit d95ac4a

Please sign in to comment.