better error messages: wrong renderer

Issue #740 resolved
Andreas Janz created an issue
Traceback (most recent call last):
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 903, in wrapper
retval = func(*args, **kwargs)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxprocessing\algorithm\classificationperformancesimplealgorithm.py", line 84, in processAlgorithm
result = self.runAlg(alg, parameters, None, feedback2, context, True)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 903, in wrapper
retval = func(*args, **kwargs)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxprocessing\enmapalgorithm.py", line 596, in runAlg
return processing.run(algOrName, parameters, onFinish, feedback, context, is_child_algorithm)
File "C:\PROGRA~1/QGIS32~1.2/apps/qgis/./python/plugins\processing\tools\general.py", line 116, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish=post_process, feedback=feedback, context=context)
File "C:\PROGRA~1/QGIS32~1.2/apps/qgis/./python/plugins\processing\core\Processing.py", line 164, in runAlgorithm
ok, msg = alg.checkParameterValues(parameters, context)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 903, in wrapper
retval = func(*args, **kwargs)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxprocessing\algorithm\classificationperformancestratifiedalgorithm.py", line 78, in checkParameterValues
self.checkCategories(parameters, context)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 903, in wrapper
retval = func(*args, **kwargs)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\enmapboxprocessing\algorithm\classificationperformancestratifiedalgorithm.py", line 60, in checkCategories
categoriesPrediction = Utils.categoriesFromPalettedRasterRenderer(classification.renderer())
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 902, in wrapper
check_argument_types(memo)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 748, in check_argument_types
raise exc from None
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 746, in check_argument_types
check_type(description, value, expected_type, memo)
File "C:\Users/Gauri/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\enmapboxplugin\site-packages\typeguard\__init__.py", line 668, in check_type
raise TypeError(
TypeError: type of argument "renderer" must be qgis._core.QgsPalettedRasterRenderer; got qgis._core.QgsSingleBandGrayRenderer instead

Comments (2)

  1. Andreas Janz reporter

    Benjamin, this should already be fixed, but I can’t say for sure without the actual data. You may test this yourself to make sure. Either in the GUI or use the unittest below:

    def test_error_messages(self):
        alg = ClassificationPerformanceSimpleAlgorithm()
        alg.initAlgorithm()
        parameters = {
            alg.P_CLASSIFICATION: enmap,
            alg.P_REFERENCE: landcover_map_l3,
            alg.P_OPEN_REPORT: False,
            alg.P_OUTPUT_REPORT: c + '/vsimem/report.html',
        }
        try:
            self.runalg(alg, parameters)
        except QgsProcessingException as error:
            self.assertEqual(
                str(error),
                'Unable to execute algorithm\nInvalid classification, requires paletted/unique values renderer (Predicted classification layer)'
            )
        parameters = {
            alg.P_CLASSIFICATION: landcover_map_l3,
            alg.P_REFERENCE: enmap,
            alg.P_OPEN_REPORT: False,
            alg.P_OUTPUT_REPORT: c + '/vsimem/report2.html',
        }
        try:
            self.runalg(alg, parameters)
        except QgsProcessingException as error:
            self.assertEqual(
                str(error),
                'Unable to execute algorithm\nInvalid classification, requires paletted/unique values renderer (Observed categorized layer)'
            )
    

  2. Log in to comment