From 714dada74dcff7e06f91ab478ba983ee06b4ff5e Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 23 Feb 2023 16:09:23 +1000 Subject: [PATCH] [processing] Don't raise uncaught exceptions when trying to generate GDAL commands for invalid layers This is a partial fix, which at least removes the uncaught exception. Ideally we'd gracefully fall back to using the layer's source (even if it doesn't exist!) in the generated GDAL commands. But that's far from trivial to do. Fixes #51958 --- .../processing/algs/gdal/GdalAlgorithmDialog.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py b/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py index 4ead580c956f..770a992884d8 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py @@ -33,8 +33,11 @@ QSizePolicy, QDialogButtonBox) -from qgis.core import (QgsProcessingFeedback, - QgsProcessingParameterDefinition) +from qgis.core import ( + QgsProcessingException, + QgsProcessingFeedback, + QgsProcessingParameterDefinition +) from qgis.gui import (QgsMessageBar, QgsProjectionSelectionWidget, QgsProcessingAlgorithmDialogBase, @@ -140,9 +143,12 @@ def parametersHaveChanged(self): self.text.setPlainText('') return - commands = self.algorithm().getConsoleCommands(parameters, context, feedback, executing=False) - commands = [c for c in commands if c not in ['cmd.exe', '/C ']] - self.text.setPlainText(" ".join(commands)) + try: + commands = self.algorithm().getConsoleCommands(parameters, context, feedback, executing=False) + commands = [c for c in commands if c not in ['cmd.exe', '/C ']] + self.text.setPlainText(" ".join(commands)) + except QgsProcessingException as e: + self.text.setPlainText(str(e)) except AlgorithmDialogBase.InvalidParameterValue as e: self.text.setPlainText(self.tr("Invalid value for parameter '{0}'").format(e.parameter.description())) except AlgorithmDialogBase.InvalidOutputExtension as e: