Private
Public Access
0
0

refactor(src): narrow exception types in Phase 6 batch (8 sites across 3 files)

Migrates the 8 try/except sites in provider + adapter + orchestration
files by narrowing the exception types from broad 'except Exception' to
specific stdlib/domain exceptions.

Files and sites:
1. src/aggregate.py:50 (is_absolute_with_drive - PureWindowsPath)
   except Exception -> except (ValueError, OSError)
2. src/aggregate.py:105 (stats - ast.parse for element count)
   except Exception -> except (SyntaxError, ValueError)
3. src/aggregate.py:107 (stats outer try)
   except Exception -> except (OSError, SyntaxError)
4. src/aggregate.py:274 (file read with traceback)
   except Exception -> except (OSError, UnicodeDecodeError)
5. src/aggregate.py:446 (AST skeleton fallback)
   except Exception -> except (AttributeError, TypeError, ValueError)
6. src/multi_agent_conductor.py:317 (persona load fallback)
   except: -> except (OSError, KeyError, AttributeError, TypeError)
7. src/multi_agent_conductor.py:467 (persona apply with print)
   except Exception -> except (OSError, KeyError, AttributeError, TypeError)
8. src/multi_agent_conductor.py:517 (file view injection)
   except Exception -> except (OSError, UnicodeDecodeError, AttributeError, TypeError)
9. src/multi_agent_conductor.py:635 (response push with traceback)
   except Exception -> except (OSError, TypeError, AttributeError)
10. src/models.py:1081 (MCP config load)
    except Exception -> except (OSError, json.JSONDecodeError, UnicodeDecodeError)

Decisions (documented as no-op):
- src/dag_engine.py: 0 violations; 1 compliant site; no migration
- src/models.py:268 (RAISE AttributeError): legitimate __getattr__ pattern; keep
- src/gemini_cli_adapter.py:173-174 (RAISE): try/except + raise for SDK
  exception conversion; keep as-is (cascading if changed)
- src/conductor_tech_lead.py:120 UNCLEAR (Phase 2 decision): keep
- src/openai_compatible.py:87 UNCLEAR (Phase 2 decision): keep

Tests verified:
- tests/test_aggregate_flags.py (2 tests) PASS
- tests/test_context_composition_phase6.py (9 tests) PASS
- tests/test_tiered_context.py (5 tests) PASS
- tests/test_ui_summary_only_removal.py (6 tests) PASS
- tests/test_orchestration_logic.py (8 tests) PASS
- tests/test_dag_engine.py (9 tests) PASS
- tests/test_conductor_tech_lead.py (9 tests) PASS
This commit is contained in:
2026-06-17 19:18:09 -04:00
parent 0ad67cef1e
commit f4a445bd4b
3 changed files with 10 additions and 10 deletions
+5 -5
View File
@@ -47,7 +47,7 @@ def is_absolute_with_drive(entry: str) -> bool:
try:
p = PureWindowsPath(entry)
return p.drive != ""
except Exception:
except (ValueError, OSError):
return False
def resolve_paths(base_dir: Path, entry: str) -> list[Path]:
@@ -100,9 +100,9 @@ def compute_file_stats(abs_path: str) -> dict[str, int]:
try:
tree = ast.parse(content)
stats["ast_elements"] = sum(1 for node in ast.walk(tree) if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)))
except Exception:
except (SyntaxError, ValueError):
pass
except Exception:
except (OSError, SyntaxError):
pass
return stats
@@ -271,7 +271,7 @@ def build_file_items(base_dir: Path, files: list[str | dict[str, Any]]) -> list[
content = f"ERROR: file not found: {path}"
mtime = 0.0
error = True
except Exception as e:
except (OSError, UnicodeDecodeError) as e:
content = f"ERROR reading {path}:\n{traceback.format_exc()}"
mtime = 0.0
error = True
@@ -443,7 +443,7 @@ def build_tier3_context(file_items: list[dict[str, Any]], screenshot_base_dir: P
try:
skeleton = parser.get_skeleton(content)
sections.append(f"### `{original}` (AST Skeleton)\n\n```python\n{skeleton}\n```")
except Exception:
except (AttributeError, TypeError, ValueError):
sections.append(f"### `{original}`\n\n{summarize.summarise_file(path, content)}")
else:
sections.append(f"### `{original}`\n\n{summarize.summarise_file(path, content)}")