mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-13 03:52:30 +08:00
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:
parent
7b8983bb34
commit
47414ffa45
@ -1102,19 +1102,19 @@ class VAE:
|
|||||||
def spacial_compression_decode(self):
|
def spacial_compression_decode(self):
|
||||||
try:
|
try:
|
||||||
return self.upscale_ratio[-1]
|
return self.upscale_ratio[-1]
|
||||||
except:
|
except (IndexError, TypeError):
|
||||||
return self.upscale_ratio
|
return self.upscale_ratio
|
||||||
|
|
||||||
def spacial_compression_encode(self):
|
def spacial_compression_encode(self):
|
||||||
try:
|
try:
|
||||||
return self.downscale_ratio[-1]
|
return self.downscale_ratio[-1]
|
||||||
except:
|
except (IndexError, TypeError):
|
||||||
return self.downscale_ratio
|
return self.downscale_ratio
|
||||||
|
|
||||||
def temporal_compression_decode(self):
|
def temporal_compression_decode(self):
|
||||||
try:
|
try:
|
||||||
return round(self.upscale_ratio[0](8192) / 8192)
|
return round(self.upscale_ratio[0](8192) / 8192)
|
||||||
except:
|
except (IndexError, TypeError, AttributeError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -358,7 +358,7 @@ def token_weights(string, current_weight):
|
|||||||
try:
|
try:
|
||||||
weight = float(x[xx+1:])
|
weight = float(x[xx+1:])
|
||||||
x = x[:xx]
|
x = x[:xx]
|
||||||
except:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
out += token_weights(x, weight)
|
out += token_weights(x, weight)
|
||||||
else:
|
else:
|
||||||
@ -425,7 +425,7 @@ def load_embed(embedding_name, embedding_directory, embedding_size, embed_key=No
|
|||||||
try:
|
try:
|
||||||
if os.path.commonpath((embed_dir, embed_path)) != embed_dir:
|
if os.path.commonpath((embed_dir, embed_path)) != embed_dir:
|
||||||
continue
|
continue
|
||||||
except:
|
except (ValueError, TypeError):
|
||||||
continue
|
continue
|
||||||
if not os.path.isfile(embed_path):
|
if not os.path.isfile(embed_path):
|
||||||
extensions = ['.safetensors', '.pt', '.bin']
|
extensions = ['.safetensors', '.pt', '.bin']
|
||||||
|
|||||||
@ -205,7 +205,7 @@ class LoRAAdapter(WeightAdapterBase):
|
|||||||
try:
|
try:
|
||||||
reshape = lora[reshape_name].tolist()
|
reshape = lora[reshape_name].tolist()
|
||||||
loaded_keys.add(reshape_name)
|
loaded_keys.add(reshape_name)
|
||||||
except:
|
except (AttributeError, TypeError):
|
||||||
pass
|
pass
|
||||||
weights = (lora[A_name], lora[B_name], alpha, mid, dora_scale, reshape)
|
weights = (lora[A_name], lora[B_name], alpha, mid, dora_scale, reshape)
|
||||||
loaded_keys.add(A_name)
|
loaded_keys.add(A_name)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user