REDcatch / Volume_calculation_for_QGIS3

GNU General Public License v3.0
8 stars 7 forks source link

Error handling improvements #9

Open AlisterH opened 1 year ago

AlisterH commented 1 year ago

Trying to debug the crashes in the other ticket, I've noticed some situations where it doesn't crash QGIS, but the error handling could be improved:

The errors are:

An error has occurred while executing Python code: 

IndexError: list index out of range 
Traceback (most recent call last):
  File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 466, in workflow
    self.gatherInputInfo()
  File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 511, in gatherInputInfo
    vector_layer = QgsProject.instance().mapLayersByName(self.dlg.mFieldComboPolygon.currentText())[0]
IndexError: list index out of range

And

2022-09-08T13:09:16     WARNING    Traceback (most recent call last):
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 474, in workflow
              self.doSimpleWorkflow()
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 477, in doSimpleWorkflow
              self.getVolumeSimple()
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 625, in getVolumeSimple
              internal_external_map[feature.id()].append(feature.attributes()[index])
             IndexError: list index out of range
AlisterH commented 1 year ago

Actually, one of those errors might have been in yet another situation, because this is what I get now in the third situation:

2022-09-08T13:24:01     WARNING    Traceback (most recent call last):
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 366, in calculationFinished
              self.writeResultsToLayer()
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 452, in writeResultsToLayer
              with edit(self.current_task_options.vector_layer):
              File "C:\PROGRA~1/QGIS32~1.2/apps/qgis/./python\qgis\core\additions\edit.py", line 38, in __enter__
              assert self.layer.startEditing()
             AssertionError
AlisterH commented 1 year ago

At some point I also saw this error, but I lost track of the situation that it occurred in:

 2022-09-08T12:46:58     WARNING    Traceback (most recent call last):
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 474, in workflow
              self.doSimpleWorkflow()
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 477, in doSimpleWorkflow
              self.getVolumeSimple()
              File "C:\Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\volume_calculation_tool\volume_calculation_tool.py", line 629, in getVolumeSimple
              absolute_avg_height = abs(internal_external_map[key][1] - internal_external_map[key][2])
             TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
distbug commented 1 year ago

Yeah, agreed error handling/feedback should be improved. At the moment the plugin expects the user to not do anything it is not designed to do. There are also checks missing.