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
This commit is contained in:
Xiao Ji Ji 2026-03-18 14:39:46 +00:00
parent 7b8983bb34
commit 47414ffa45
3 changed files with 6 additions and 6 deletions

View File

@ -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

View File

@ -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']

View File

@ -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)