From 029f0175960631a22b4fed8bec2be7006dc66649 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Tue, 24 Feb 2026 21:43:49 +0000 Subject: [PATCH] fix: replace bare except clauses with specific exception types Bare 'except:' catches BaseException including SystemExit and KeyboardInterrupt, which can mask critical errors and make debugging harder. Replace with appropriate specific exception types: - browser_env.py: except Exception (Playwright timeout/navigation) - local_env.py: except (subprocess.SubprocessError, OSError) - registry.py: except (TypeError, OSError) for inspect.getfile() --- autoagent/environment/browser_env.py | 4 ++-- autoagent/environment/local_env.py | 2 +- autoagent/registry.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autoagent/environment/browser_env.py b/autoagent/environment/browser_env.py index 45cefb0..13fbe0c 100644 --- a/autoagent/environment/browser_env.py +++ b/autoagent/environment/browser_env.py @@ -256,7 +256,7 @@ def _click_id(bid: str, button: Literal["left", "middle", "right"] = "left"): # 等待页面完全加载 # 增加等待时间,确保页面完全加载 page.wait_for_load_state("networkidle", timeout=3000) - except: + except Exception: pass return @@ -322,7 +322,7 @@ def tryToClickChallenge(this_page): (!document.body.textContent.includes("请完成以下操作,验证您是真人。") && !document.body.textContent.includes("Verify you are human by completing the action below.")) """, timeout=20000) - except: + except Exception: print("等待验证超时") # 检查是否仍在验证页面 diff --git a/autoagent/environment/local_env.py b/autoagent/environment/local_env.py index 5143b54..ec96a5f 100644 --- a/autoagent/environment/local_env.py +++ b/autoagent/environment/local_env.py @@ -66,7 +66,7 @@ def _find_conda_sh(self) -> str: conda_sh = Path(base_path) / "etc" / "profile.d" / "conda.sh" if conda_sh.exists(): return str(conda_sh) - except: + except (subprocess.SubprocessError, OSError): pass # 3. If all fails, return None and handle in run_command diff --git a/autoagent/registry.py b/autoagent/registry.py index ad67bab..a17f924 100644 --- a/autoagent/registry.py +++ b/autoagent/registry.py @@ -97,7 +97,7 @@ def wrapped_func(*args, **kwargs): wrapped_func = func try: file_path = os.path.abspath(inspect.getfile(func)) - except: + except (TypeError, OSError): file_path = "Unknown" # 获取函数信息