refactor(errors): replace silent exception handling in core packages
This commit is contained in:
1 parent
584bb2d09c
commit
47e7cb6620
21 files changed
+132
-58
No files matched your search
@@ -170,7 +170,8 @@ def doctor_command(
|
||||
state = parts[1]
|
||||
extra = " ".join(parts[2:])
|
||||
devices_info.append((serial, state, extra))
|
||||
except Exception:
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
# adb probe failed or timed out; report as "no devices detected".
|
||||
pass
|
||||
|
||||
if devices_info:
|
||||
|
||||
@@ -78,7 +78,8 @@ def init_command() -> None:
|
||||
serial = parts[0]
|
||||
extra = " ".join(parts[2:])
|
||||
detected_devices.append((serial, extra))
|
||||
except Exception:
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
# adb probe failed or timed out; continue setup with no devices.
|
||||
pass
|
||||
|
||||
selected_serial = ""
|
||||
|
||||
@@ -166,7 +166,8 @@ def _parse_json_lenient(text: str) -> dict | None:
|
||||
try:
|
||||
data = json.loads(text)
|
||||
return data if isinstance(data, dict) else None
|
||||
except Exception:
|
||||
except ValueError:
|
||||
# Not strict JSON; fall through to the lenient JSONC cleanup below.
|
||||
pass
|
||||
# Remove // single-line comments
|
||||
cleaned = re.sub(r"//.*", "", text)
|
||||
@@ -215,8 +216,11 @@ def _merge_json_file(
|
||||
try:
|
||||
backup_path.write_text(raw_text, encoding="utf-8")
|
||||
logger.warning(f"Existing JSON in {file_path} could not be parsed; backup created at {backup_path}")
|
||||
except Exception:
|
||||
pass
|
||||
except OSError as exc:
|
||||
logger.warning(
|
||||
f"Existing JSON in {file_path} could not be parsed AND the backup to"
|
||||
f" {backup_path} failed ({exc}); the original content will be overwritten."
|
||||
)
|
||||
|
||||
for remove_path in remove_paths:
|
||||
parent = data
|
||||
@@ -316,8 +320,10 @@ def _merge_codex_toml(file_path: Path, server_config: dict) -> bool:
|
||||
backup_path = file_path.with_suffix(file_path.suffix + ".bak")
|
||||
backup_path.write_text(file_path.read_text(encoding="utf-8"), encoding="utf-8")
|
||||
logger.warning(f"Could not update {file_path}; backup created at {backup_path}: {e}")
|
||||
except Exception:
|
||||
pass
|
||||
except (OSError, UnicodeDecodeError) as backup_exc:
|
||||
logger.warning(
|
||||
f"Could not update {file_path} ({e}); backup also failed: {backup_exc}"
|
||||
)
|
||||
else:
|
||||
logger.warning(f"Could not create Codex MCP config file {file_path}: {e}")
|
||||
return False
|
||||
@@ -394,7 +400,8 @@ def _write_rule_file(file_path: Path, content: str) -> bool:
|
||||
try:
|
||||
if file_path.read_text(encoding="utf-8") == new_text:
|
||||
return True
|
||||
except Exception:
|
||||
except (OSError, UnicodeDecodeError):
|
||||
# Unreadable existing file: skip the no-op check and rewrite it.
|
||||
pass
|
||||
file_path.write_text(new_text, encoding="utf-8")
|
||||
return True
|
||||
@@ -419,7 +426,8 @@ def _write_cursor_mdc(file_path: Path, content: str) -> bool:
|
||||
try:
|
||||
if file_path.read_text(encoding="utf-8") == new_text:
|
||||
return True
|
||||
except Exception:
|
||||
except (OSError, UnicodeDecodeError):
|
||||
# Unreadable existing file: skip the no-op check and rewrite it.
|
||||
pass
|
||||
file_path.write_text(new_text, encoding="utf-8")
|
||||
return True
|
||||
|
||||
@@ -408,8 +408,9 @@ def run_command(
|
||||
host=settings.ADB_HOST or "localhost",
|
||||
port=settings.ADB_PORT or 5037,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as exc:
|
||||
# Optional cosmetic device-status display; run continues without it.
|
||||
logger.debug(f"Could not create ADB client for device status display: {exc}")
|
||||
|
||||
display_device_status(console, adb_client=adb_client)
|
||||
|
||||
@@ -420,7 +421,9 @@ def run_command(
|
||||
original_sigterm = signal.signal(
|
||||
signal.SIGTERM, lambda s, f: (_ for _ in ()).throw(KeyboardInterrupt())
|
||||
)
|
||||
except Exception:
|
||||
except (ValueError, OSError, RuntimeError):
|
||||
# Not the main thread or platform does not support SIGTERM handlers;
|
||||
# run proceeds without the graceful-cancel hook.
|
||||
pass
|
||||
|
||||
try:
|
||||
@@ -471,7 +474,8 @@ def run_command(
|
||||
try:
|
||||
if original_sigterm is not None and hasattr(signal, "SIGTERM"):
|
||||
signal.signal(signal.SIGTERM, original_sigterm)
|
||||
except Exception:
|
||||
except (ValueError, OSError, RuntimeError):
|
||||
# Best-effort restore of the previous handler on the way out.
|
||||
pass
|
||||
if cancelled:
|
||||
raise SystemExit(130)
|
||||
@@ -265,7 +265,8 @@ def status_command(
|
||||
try:
|
||||
dt = datetime.datetime.fromtimestamp(metadata["started_at"])
|
||||
started_at_str = dt.strftime("%Y-%m-%d %H:%M:%S")
|
||||
except Exception:
|
||||
except (TypeError, ValueError, OSError, OverflowError):
|
||||
# Malformed or out-of-range timestamp in metadata: show "Unknown".
|
||||
pass
|
||||
|
||||
table = Table(show_header=False, box=None, padding=(0, 2))
|
||||
|
||||
Reference in new issue
Block a user