diff --git a/metadata.txt b/metadata.txt index 16a82bf..8e77941 100644 --- a/metadata.txt +++ b/metadata.txt @@ -2,7 +2,7 @@ name=Puentes description=Run external Python files inside QGIS. -version=1.0.0 +version=1.0.1 qgisMinimumVersion=3.0 qgisMaximumVersion=3.99 author=Gabriel De Luca @@ -18,6 +18,7 @@ tags=python, script, utilities. homepage=https://github.com/caprieldeluca/puentes changelog= + 1.0.1 - Fix format_exception call for Python < 3.10. 1.0.0 - First stable release. 0.3.1 - Plog last traceback instead of raise exception on Python errors. 0.3.0 - Move settings to plugin/puentes, only store file_path. diff --git a/plugin.py b/plugin.py index bacba89..ab9a8e3 100644 --- a/plugin.py +++ b/plugin.py @@ -16,7 +16,7 @@ import io from pathlib import Path import runpy -import traceback +import sys, traceback from qgis.core import QgsApplication from qgis.PyQt.QtGui import QIcon @@ -94,8 +94,19 @@ def run_command(self): runpy.run_path(self.file_path, init_globals={'plog': plog}) QSettings().setValue('plugins/puentes/file_path', self.file_path) - except Exception as e: - plog(*traceback.format_exception(e, limit=-1)) + except Exception: + # From Python 3.10 only exc_value (the Exception instance) is needed, + # exc_type and exc_traceback are preserved for backwards compatibility + exc_type, exc_value, exc_traceback = sys.exc_info() + # Create a StackSummary object to get its length + stack_length = len(traceback.extract_tb(exc_traceback)) + # Define limit as negative index to remove first frame + # (this file exception) from the stacktrace + limit = 1 - stack_length + plog(*traceback.format_exception(exc_type, + exc_value, + exc_traceback, + limit=limit)) #####