From 47414ffa452cc3c8c8015c038ff01260c7a5a0bb Mon Sep 17 00:00:00 2001 From: Xiao Ji Ji Date: Wed, 18 Mar 2026 14:39:46 +0000 Subject: [PATCH] fix: replace bare except with specific exception types Replace bare except clauses with specific exception types in: - comfy/sd.py: VAE.spacial_compression_decode/encode and temporal_compression_decode - comfy/sd1_clip.py: token_weights and load_embed functions - comfy/weight_adapter/lora.py: LoRAAdapter.load This ensures that: - Only relevant exceptions are caught (not SystemExit, KeyboardInterrupt) - Debugging is easier as unexpected errors will propagate - Follows Python best practices for exception handling --- comfy/sd.py | 6 +++--- comfy/sd1_clip.py | 4 ++-- comfy/weight_adapter/lora.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/comfy/sd.py b/comfy/sd.py index adcd67767..17f3e5395 100644 --- a/comfy/sd.py +++ b/comfy/sd.py @@ -1102,19 +1102,19 @@ class VAE: def spacial_compression_decode(self): try: return self.upscale_ratio[-1] - except: + except (IndexError, TypeError): return self.upscale_ratio def spacial_compression_encode(self): try: return self.downscale_ratio[-1] - except: + except (IndexError, TypeError): return self.downscale_ratio def temporal_compression_decode(self): try: return round(self.upscale_ratio[0](8192) / 8192) - except: + except (IndexError, TypeError, AttributeError): return None diff --git a/comfy/sd1_clip.py b/comfy/sd1_clip.py index d89550840..3ea4ed48a 100644 --- a/comfy/sd1_clip.py +++ b/comfy/sd1_clip.py @@ -358,7 +358,7 @@ def token_weights(string, current_weight): try: weight = float(x[xx+1:]) x = x[:xx] - except: + except ValueError: pass out += token_weights(x, weight) else: @@ -425,7 +425,7 @@ def load_embed(embedding_name, embedding_directory, embedding_size, embed_key=No try: if os.path.commonpath((embed_dir, embed_path)) != embed_dir: continue - except: + except (ValueError, TypeError): continue if not os.path.isfile(embed_path): extensions = ['.safetensors', '.pt', '.bin'] diff --git a/comfy/weight_adapter/lora.py b/comfy/weight_adapter/lora.py index 8e1261a12..678bfbebf 100644 --- a/comfy/weight_adapter/lora.py +++ b/comfy/weight_adapter/lora.py @@ -205,7 +205,7 @@ class LoRAAdapter(WeightAdapterBase): try: reshape = lora[reshape_name].tolist() loaded_keys.add(reshape_name) - except: + except (AttributeError, TypeError): pass weights = (lora[A_name], lora[B_name], alpha, mid, dora_scale, reshape) loaded_keys.add(A_name)