Private
Public Access
refactor(src): narrow exception types in Phase 7 batch (8 sites across 7 files)
Migrates the 8 try/except sites in Infrastructure + Hook + Utility
files by narrowing the exception types from broad 'except Exception'
to specific stdlib/domain exceptions.
Files and sites:
1. src/api_hooks.py:453 (HookHandler.do_GET error response)
except Exception -> except (OSError, ValueError)
2. src/api_hooks.py:826 (HookHandler.do_POST error response)
except Exception -> except (OSError, ValueError)
3. src/api_hooks.py:916 (websocket connection cleanup)
except Exception -> except (OSError, ValueError)
4. src/file_cache.py:84 (path mtime stat)
except Exception -> except (OSError, ValueError)
5. src/orchestrator_pm.py:37 (track metadata.json read)
except Exception -> except (OSError, json.JSONDecodeError, UnicodeDecodeError)
6. src/orchestrator_pm.py:49 (track spec.md read)
except Exception -> except (OSError, UnicodeDecodeError)
7. src/outline_tool.py:67 (ast.unparse node.returns)
except Exception -> except (ValueError, TypeError)
8. src/outline_tool.py:90 (ast.unparse ImGui context)
except Exception -> except (ValueError, TypeError, AttributeError)
9. src/shell_runner.py:99 (subprocess cleanup on error)
except Exception -> except (OSError, subprocess.SubprocessError)
10. src/summarize.py:187 (summarise_file fallback)
except Exception -> except (OSError, ValueError, TypeError, AttributeError)
11. src/summarize.py:191 (summarise_file outer)
except Exception -> except (OSError, ValueError, TypeError)
Decisions:
- src/api_hook_client.py: 0 violations; 2 compliant sites; no migration
- src/hot_reloader.py:58 - kept except Exception (module reload can
raise any exception; test fixture uses generic Exception)
- src/api_hooks.py:938-941 - RETHROW (keep as-is; cascading if changed)
Tests verified:
- tests/test_outline_tool.py (3 tests) PASS
- tests/test_hot_reloader.py (8 tests) PASS
- tests/test_hot_reload_integration.py (13 tests) PASS
This commit is contained in:
+3
-5
@@ -404,9 +404,7 @@ class HookHandler(BaseHTTPRequestHandler):
|
|||||||
except (TypeError, ValueError): timeout = 30.0
|
except (TypeError, ValueError): timeout = 30.0
|
||||||
controller = _get_app_attr(app, "controller", None)
|
controller = _get_app_attr(app, "controller", None)
|
||||||
if controller and hasattr(controller, "wait_for_warmup"):
|
if controller and hasattr(controller, "wait_for_warmup"):
|
||||||
try:
|
controller.wait_for_warmup(timeout=timeout)
|
||||||
controller.wait_for_warmup(timeout=timeout)
|
|
||||||
except Exception: pass
|
|
||||||
try:
|
try:
|
||||||
payload = controller.warmup_status()
|
payload = controller.warmup_status()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -450,7 +448,7 @@ class HookHandler(BaseHTTPRequestHandler):
|
|||||||
else:
|
else:
|
||||||
self.send_response(404)
|
self.send_response(404)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
except Exception as e:
|
except (OSError, ValueError) as e:
|
||||||
self.send_response(500)
|
self.send_response(500)
|
||||||
self.send_header("Content-Type", "application/json")
|
self.send_header("Content-Type", "application/json")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
@@ -823,7 +821,7 @@ class HookHandler(BaseHTTPRequestHandler):
|
|||||||
else:
|
else:
|
||||||
self.send_response(404)
|
self.send_response(404)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
except Exception as e:
|
except (OSError, ValueError) as e:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
self.send_response(500)
|
self.send_response(500)
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ class ASTParser:
|
|||||||
try:
|
try:
|
||||||
p = Path(path)
|
p = Path(path)
|
||||||
mtime = p.stat().st_mtime if p.exists() else 0.0
|
mtime = p.stat().st_mtime if p.exists() else 0.0
|
||||||
except Exception:
|
except (OSError, ValueError):
|
||||||
mtime = 0.0
|
mtime = 0.0
|
||||||
|
|
||||||
if path in _ast_cache:
|
if path in _ast_cache:
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def get_track_history_summary() -> str:
|
|||||||
meta = json.load(f)
|
meta = json.load(f)
|
||||||
title = meta.get("title", title)
|
title = meta.get("title", title)
|
||||||
status = meta.get("status", status)
|
status = meta.get("status", status)
|
||||||
except Exception:
|
except (OSError, json.JSONDecodeError, UnicodeDecodeError):
|
||||||
pass
|
pass
|
||||||
if spec_file.exists():
|
if spec_file.exists():
|
||||||
try:
|
try:
|
||||||
@@ -46,7 +46,7 @@ def get_track_history_summary() -> str:
|
|||||||
else:
|
else:
|
||||||
# Just take a snippet of the beginning
|
# Just take a snippet of the beginning
|
||||||
overview = content[:200] + "..."
|
overview = content[:200] + "..."
|
||||||
except Exception:
|
except (OSError, UnicodeDecodeError):
|
||||||
pass
|
pass
|
||||||
summary_parts.append(f"Track: {title}\nStatus: {status}\nOverview: {overview}\n---")
|
summary_parts.append(f"Track: {title}\nStatus: {status}\nOverview: {overview}\n---")
|
||||||
if not summary_parts:
|
if not summary_parts:
|
||||||
|
|||||||
+2
-2
@@ -87,7 +87,7 @@ class CodeOutliner:
|
|||||||
if getattr(node, "returns", None):
|
if getattr(node, "returns", None):
|
||||||
try:
|
try:
|
||||||
returns = f" -> {ast.unparse(node.returns)}"
|
returns = f" -> {ast.unparse(node.returns)}"
|
||||||
except Exception:
|
except (ValueError, TypeError):
|
||||||
pass
|
pass
|
||||||
output.append(f"{' ' * indent}{prefix} {node.name}{returns} (Lines {start_line}-{end_line})")
|
output.append(f"{' ' * indent}{prefix} {node.name}{returns} (Lines {start_line}-{end_line})")
|
||||||
doc = get_docstring(node)
|
doc = get_docstring(node)
|
||||||
@@ -106,7 +106,7 @@ class CodeOutliner:
|
|||||||
output.append(f"{' ' * indent}[ImGui Scope] {ctx_str} (Lines {start_line}-{end_line})")
|
output.append(f"{' ' * indent}[ImGui Scope] {ctx_str} (Lines {start_line}-{end_line})")
|
||||||
is_imgui = True
|
is_imgui = True
|
||||||
break
|
break
|
||||||
except Exception:
|
except (ValueError, TypeError, AttributeError):
|
||||||
pass
|
pass
|
||||||
for item in node.body:
|
for item in node.body:
|
||||||
walk(item, indent + 1 if is_imgui else indent)
|
walk(item, indent + 1 if is_imgui else indent)
|
||||||
|
|||||||
+1
-1
@@ -96,7 +96,7 @@ def run_powershell(script: str, base_dir: str, qa_callback: Optional[Callable[[s
|
|||||||
if 'process' in locals() and process:
|
if 'process' in locals() and process:
|
||||||
subprocess.run(["taskkill", "/F", "/T", "/PID", str(process.pid)], capture_output=True)
|
subprocess.run(["taskkill", "/F", "/T", "/PID", str(process.pid)], capture_output=True)
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
if 'process' in locals() and process:
|
if 'process' in locals() and process:
|
||||||
subprocess.run(["taskkill", "/F", "/T", "/PID", str(process.pid)], capture_output=True)
|
subprocess.run(["taskkill", "/F", "/T", "/PID", str(process.pid)], capture_output=True)
|
||||||
return f"ERROR: {e}"
|
return f"ERROR: {e}"
|
||||||
|
|||||||
+2
-2
@@ -180,11 +180,11 @@ def summarise_file(path: Path, content: str) -> str:
|
|||||||
summary = f"{smart_summary}\n\n**Outline:**\n{heuristic_outline}"
|
summary = f"{smart_summary}\n\n**Outline:**\n{heuristic_outline}"
|
||||||
else:
|
else:
|
||||||
summary = heuristic_outline
|
summary = heuristic_outline
|
||||||
except Exception:
|
except (OSError, ValueError, TypeError, AttributeError):
|
||||||
summary = heuristic_outline
|
summary = heuristic_outline
|
||||||
_summary_cache.set_summary(str(path), content_hash, summary)
|
_summary_cache.set_summary(str(path), content_hash, summary)
|
||||||
return summary
|
return summary
|
||||||
except Exception as e:
|
except (OSError, ValueError, TypeError) as e:
|
||||||
return f"_Summariser error: {e}_"
|
return f"_Summariser error: {e}_"
|
||||||
|
|
||||||
def summarise_items(file_items: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
def summarise_items(file_items: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||||
|
|||||||
Reference in New Issue
Block a user