From f278a2e13cef9d9832d2d6779dcce5a4791c808d Mon Sep 17 00:00:00 2001 From: Maddy Guthridge Date: Sun, 23 Jun 2024 16:53:21 +1000 Subject: [PATCH] Also catch RuntimeError exceptions --- src/common/activity_state.py | 6 +++--- src/common/states/main_state.py | 4 ++-- src/common/util/api_fixes.py | 4 ++-- src/plugs/mapping_strategies/note_strategy.py | 2 +- src/plugs/special/activity_switcher.py | 8 ++++---- src/plugs/windows/channel_rack/omni.py | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/common/activity_state.py b/src/common/activity_state.py index bf32558c..2cf91cdc 100644 --- a/src/common/activity_state.py +++ b/src/common/activity_state.py @@ -95,7 +95,7 @@ def _forcePlugUpdate(self) -> None: self._plugin = plugin try: self._plugin_name = plugins.getPluginName(*plugin) - except TypeError: + except (TypeError, RuntimeError): self._plugin_name = "" if len(plugin) == 1: self._generator = plugin @@ -116,7 +116,7 @@ def tick(self) -> None: try: if self._plugin_name != plugins.getPluginName(*self._plugin): self._do_update = True - except TypeError: + except (TypeError, RuntimeError): pass if self._do_update: # Manually update plugin using selection @@ -136,7 +136,7 @@ def tick(self) -> None: self._plugin = plugin try: self._plugin_name = plugins.getPluginName(*plugin) - except TypeError: + except (TypeError, RuntimeError): self._plugin_name = "" # Ignore typing because len(plugin) doesn't narrow types in # mypy diff --git a/src/common/states/main_state.py b/src/common/states/main_state.py index 3b8afef3..5eda53ee 100644 --- a/src/common/states/main_state.py +++ b/src/common/states/main_state.py @@ -73,7 +73,7 @@ def tick(self) -> None: if isinstance(plug_idx, tuple): try: plug_id = plugins.getPluginName(*plug_idx) - except TypeError: + except (TypeError, RuntimeError): # Plugin not valid plug_id = "" plug = common.ExtensionManager.plugins.get( @@ -146,7 +146,7 @@ def processEvent(self, event: FlMidiMsg) -> None: if isinstance(plug_idx, tuple): try: plug_id = plugins.getPluginName(*plug_idx) - except TypeError: + except (TypeError, RuntimeError): # Plugin not valid plug_id = "" plug = common.ExtensionManager.plugins.get( diff --git a/src/common/util/api_fixes.py b/src/common/util/api_fixes.py index 436ab78d..8e14d096 100644 --- a/src/common/util/api_fixes.py +++ b/src/common/util/api_fixes.py @@ -125,7 +125,7 @@ def isPluginVst(index: PluginIndex) -> bool: """ try: return plugins.getParamCount(*index) > PARAM_CC_START - except TypeError: + except (TypeError, RuntimeError): return False @@ -139,7 +139,7 @@ def catchUnsafeOperation(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except TypeError as e: + except (TypeError, RuntimeError) as e: if e.args != ("Operation unsafe at current time",): raise e return wrapper diff --git a/src/plugs/mapping_strategies/note_strategy.py b/src/plugs/mapping_strategies/note_strategy.py index a3802007..a2f99e9a 100644 --- a/src/plugs/mapping_strategies/note_strategy.py +++ b/src/plugs/mapping_strategies/note_strategy.py @@ -44,7 +44,7 @@ def noteCallback( ) -> bool: try: i = channels.getChannelIndex(*getContext().activity.getGenerator()) - except TypeError: + except (TypeError, RuntimeError): # Index out of range - we're using a plugin from a different group i = channels.channelNumber() channels.midiNoteOn( diff --git a/src/plugs/special/activity_switcher.py b/src/plugs/special/activity_switcher.py index 0d757073..bfa29865 100644 --- a/src/plugs/special/activity_switcher.py +++ b/src/plugs/special/activity_switcher.py @@ -51,14 +51,14 @@ def getActivityColor(activity: SafeIndex) -> Color: # Generator -> channel color try: return Color.fromInteger(channels.getChannelColor(*activity)) - except TypeError: + except (TypeError, RuntimeError): # Prevent issues if we deleted stuff return Color.BLACK else: # Effect -> track color try: return Color.fromInteger(mixer.getTrackColor(activity[0])) - except TypeError: + except (TypeError, RuntimeError): return Color.BLACK @@ -78,7 +78,7 @@ def getActivityName(activity: SafeIndex) -> str: if len(activity) == 1: try: return channels.getChannelName(*activity) - except TypeError: + except (TypeError, RuntimeError): # Prevent issues if we deleted stuff return "" else: @@ -88,7 +88,7 @@ def getActivityName(activity: SafeIndex) -> str: f"{mixer.getTrackName(activity[0])}: " # type: ignore f"{plugins.getPluginName(*activity, True)}" ) - except TypeError: + except (TypeError, RuntimeError): # Prevent issues if we deleted stuff return "" diff --git a/src/plugs/windows/channel_rack/omni.py b/src/plugs/windows/channel_rack/omni.py index be502826..227ddcc7 100644 --- a/src/plugs/windows/channel_rack/omni.py +++ b/src/plugs/windows/channel_rack/omni.py @@ -52,7 +52,7 @@ def drumPads( idx = channels.getChannelIndex( coordToIndex(control.getShadow()) ) - except TypeError: # Index out of range + except (TypeError, RuntimeError): # Index out of range return True channels.midiNoteOn( idx,