fixed: avoid except:

fixed: prestartup_script - remove useless exception handling when fallback resolving comfy_path
This commit is contained in:
Dr.Lt.Data
2025-04-21 12:42:50 +09:00
committed by bymyself
parent 31de92a7ef
commit 276ccca4f6
13 changed files with 101 additions and 134 deletions

View File

@@ -63,7 +63,7 @@ def get_default_custom_nodes_path():
try:
import folder_paths
default_custom_nodes_path = folder_paths.get_folder_paths("custom_nodes")[0]
except:
except Exception:
default_custom_nodes_path = os.path.abspath(os.path.join(manager_util.comfyui_manager_path, '..'))
return default_custom_nodes_path
@@ -73,7 +73,7 @@ def get_custom_nodes_paths():
try:
import folder_paths
return folder_paths.get_folder_paths("custom_nodes")
except:
except Exception:
custom_nodes_path = os.path.abspath(os.path.join(manager_util.comfyui_manager_path, '..'))
return [custom_nodes_path]
@@ -110,11 +110,11 @@ def check_invalid_nodes():
try:
import folder_paths
except:
except Exception:
try:
sys.path.append(context.comfy_path)
import folder_paths
except:
except Exception:
raise Exception(f"Invalid COMFYUI_FOLDERS_BASE_PATH: {context.comfy_path}")
def check(root):
@@ -778,7 +778,7 @@ class UnifiedManager:
if 'id' in x:
if x['id'] not in res:
res[x['id']] = (x, True)
except:
except Exception:
logging.error(f"[ComfyUI-Manager] broken item:{x}")
return res
@@ -831,7 +831,7 @@ class UnifiedManager:
def safe_version(ver_str):
try:
return version.parse(ver_str)
except:
except Exception:
return version.parse("0.0.0")
def execute_install_script(self, url, repo_path, instant_execution=False, lazy_mode=False, no_deps=False):
@@ -1499,7 +1499,7 @@ def identify_node_pack_from_path(fullpath):
if github_id is None:
try:
github_id = os.path.basename(repo_url)
except:
except Exception:
logging.warning(f"[ComfyUI-Manager] unexpected repo url: {repo_url}")
github_id = module_name
@@ -1724,27 +1724,27 @@ def switch_to_default_branch(repo):
default_branch = repo.git.symbolic_ref(f'refs/remotes/{remote_name}/HEAD').replace(f'refs/remotes/{remote_name}/', '')
repo.git.checkout(default_branch)
return True
except:
except Exception:
# try checkout master
# try checkout main if failed
try:
repo.git.checkout(repo.heads.master)
return True
except:
except Exception:
try:
if remote_name is not None:
repo.git.checkout('-b', 'master', f'{remote_name}/master')
return True
except:
except Exception:
try:
repo.git.checkout(repo.heads.main)
return True
except:
except Exception:
try:
if remote_name is not None:
repo.git.checkout('-b', 'main', f'{remote_name}/main')
return True
except:
except Exception:
pass
print("[ComfyUI Manager] Failed to switch to the default branch")
@@ -1795,7 +1795,7 @@ def try_install_script(url, repo_path, install_cmd, instant_execution=False):
print(f"[WARN] ComfyUI-Manager: Your ComfyUI version ({comfy_ui_revision})[{comfy_ui_commit_datetime.date()}] is too old. Please update to the latest version.")
print("[WARN] The extension installation feature may not work properly in the current installed ComfyUI version on Windows environment.")
print("###################################################################\n\n")
except:
except Exception:
pass
if code != 0:
@@ -2427,7 +2427,7 @@ def update_to_stable_comfyui(repo_path):
repo = git.Repo(repo_path)
try:
repo.git.checkout(repo.heads.master)
except:
except Exception:
logging.error(f"[ComfyUI-Manager] Failed to checkout 'master' branch.\nrepo_path={repo_path}\nAvailable branches:")
for branch in repo.branches:
logging.error('\t'+branch.name)
@@ -2450,7 +2450,7 @@ def update_to_stable_comfyui(repo_path):
logging.info(f"[ComfyUI-Manager] Updating ComfyUI: {current_tag} -> {latest_tag}")
repo.git.checkout(latest_tag)
return 'updated', latest_tag
except:
except Exception:
traceback.print_exc()
return "fail", None
@@ -2648,7 +2648,7 @@ async def get_current_snapshot(custom_nodes_only = False):
commit_hash = git_utils.get_commit_hash(fullpath)
url = git_utils.git_url(fullpath)
git_custom_nodes[url] = dict(hash=commit_hash, disabled=is_disabled)
except:
except Exception:
print(f"Failed to extract snapshots for the custom node '{path}'.")
elif path.endswith('.py'):
@@ -2706,7 +2706,7 @@ async def extract_nodes_from_workflow(filepath, mode='local', channel_url='defau
with open(filepath, "r", encoding="UTF-8", errors="ignore") as json_file:
try:
workflow = json.load(json_file)
except:
except Exception:
print(f"Invalid workflow file: {filepath}")
exit(-1)
@@ -2719,7 +2719,7 @@ async def extract_nodes_from_workflow(filepath, mode='local', channel_url='defau
else:
try:
workflow = json.loads(img.info['workflow'])
except:
except Exception:
print(f"This is not a valid .png file containing a ComfyUI workflow: {filepath}")
exit(-1)
@@ -2990,7 +2990,7 @@ def populate_github_stats(node_packs, json_obj_github):
v['stars'] = -1
v['last_update'] = -1
v['trust'] = False
except:
except Exception:
logging.error(f"[ComfyUI-Manager] DB item is broken:\n{v}")
@@ -3266,7 +3266,7 @@ def get_comfyui_versions(repo=None):
try:
remote = get_remote_name(repo)
repo.remotes[remote].fetch()
except:
except Exception:
logging.error("[ComfyUI-Manager] Failed to fetch ComfyUI")
versions = [x.name for x in repo.tags if x.name.startswith('v')]
@@ -3335,5 +3335,5 @@ def repo_switch_commit(repo_path, commit_hash):
repo.git.checkout(commit_hash)
return True
except:
except Exception:
return None

View File

@@ -220,7 +220,7 @@ def print_comfyui_version():
try:
if not os.environ.get('__COMFYUI_DESKTOP_VERSION__') and core.comfy_ui_commit_datetime.date() < core.comfy_ui_required_commit_datetime.date():
logging.warning(f"\n\n## [WARN] ComfyUI-Manager: Your ComfyUI version ({core.comfy_ui_revision})[{core.comfy_ui_commit_datetime.date()}] is too old. Please update to the latest version. ##\n\n")
except:
except Exception:
pass
# process on_revision_detected -->
@@ -247,7 +247,7 @@ def print_comfyui_version():
logging.info(f"### ComfyUI Version: {comfyui_tag} on '{current_branch}' | Released on '{core.comfy_ui_commit_datetime.date()}'")
else:
logging.info(f"### ComfyUI Revision: {core.comfy_ui_revision} on '{current_branch}' [{comfy_ui_hash[:8]}] | Released on '{core.comfy_ui_commit_datetime.date()}'")
except:
except Exception:
if is_detached:
logging.info(f"### ComfyUI Revision: {core.comfy_ui_revision} [{comfy_ui_hash[:8]}] *DETACHED | Released on '{core.comfy_ui_commit_datetime.date()}'")
else:
@@ -899,7 +899,7 @@ async def fetch_updates(request):
return web.Response(status=201)
return web.Response(status=200)
except:
except Exception:
traceback.print_exc()
return web.Response(status=400)
@@ -1163,7 +1163,7 @@ async def remove_snapshot(request):
os.remove(path)
return web.Response(status=200)
except:
except Exception:
return web.Response(status=400)
@@ -1189,7 +1189,7 @@ async def restore_snapshot(request):
logging.error(f"Snapshot file not found: `{path}`")
return web.Response(status=400)
except:
except Exception:
return web.Response(status=400)
@@ -1197,7 +1197,7 @@ async def restore_snapshot(request):
async def get_current_snapshot_api(request):
try:
return web.json_response(await core.get_current_snapshot(), content_type='application/json')
except:
except Exception:
return web.Response(status=400)
@@ -1206,7 +1206,7 @@ async def save_snapshot(request):
try:
await core.save_snapshot_with_postfix('snapshot')
return web.Response(status=200)
except:
except Exception:
return web.Response(status=400)
@@ -1754,7 +1754,7 @@ async def get_notice(request):
markdown_content = '<P style="text-align: center; color:red; background-color:white; font-weight:bold">Your ComfyUI isn\'t git repo.</P>' + markdown_content
elif core.comfy_ui_required_commit_datetime.date() > core.comfy_ui_commit_datetime.date():
markdown_content = '<P style="text-align: center; color:red; background-color:white; font-weight:bold">Your ComfyUI is too OUTDATED!!!</P>' + markdown_content
except:
except Exception:
pass
return web.Response(text=markdown_content, status=200)
@@ -1833,7 +1833,7 @@ async def save_component(request):
with open(filepath, 'w') as f:
json.dump(components, f, indent=4, sort_keys=True)
return web.Response(text=filepath, status=200)
except:
except Exception:
return web.Response(status=400)

View File

@@ -10,6 +10,7 @@ import hashlib
import folder_paths
from server import PromptServer
import logging
def extract_model_file_names(json_data):
@@ -73,7 +74,7 @@ def get_openart_auth():
with open(os.path.join(context.manager_files_path, ".openart_key"), "r") as f:
openart_key = f.read().strip()
return openart_key if openart_key else None
except:
except Exception:
return None
@@ -91,7 +92,7 @@ def get_matrix_auth():
"username": username,
"password": password,
}
except:
except Exception:
return None
@@ -104,7 +105,7 @@ def get_comfyworkflows_auth():
if not share_key.strip():
return None
return share_key
except:
except Exception:
return None
@@ -115,7 +116,7 @@ def get_youml_settings():
with open(os.path.join(context.manager_files_path, ".youml"), "r") as f:
youml_settings = f.read().strip()
return youml_settings if youml_settings else None
except:
except Exception:
return None
@@ -235,7 +236,7 @@ async def share_art(request):
try:
output_to_share = potential_outputs[int(selected_output_index)]
except:
except Exception:
# for now, pick the first output
output_to_share = potential_outputs[0]
@@ -352,7 +353,7 @@ async def share_art(request):
token = client.login(username=matrix_auth['username'], password=matrix_auth['password'])
if not token:
return web.json_response({"error": "Invalid Matrix credentials."}, content_type='application/json', status=400)
except:
except Exception:
return web.json_response({"error": "Invalid Matrix credentials."}, content_type='application/json', status=400)
matrix = MatrixHttpApi(homeserver, token=token)
@@ -371,9 +372,8 @@ async def share_art(request):
matrix.send_message(comfyui_share_room_id, text_content)
matrix.send_content(comfyui_share_room_id, mxc_url, filename, 'm.image')
matrix.send_content(comfyui_share_room_id, workflow_json_mxc_url, 'workflow.json', 'm.file')
except:
import traceback
traceback.print_exc()
except Exception:
logging.exception("An error occurred")
return web.json_response({"error": "An error occurred when sharing your art to Matrix."}, content_type='application/json', status=500)
return web.json_response({