Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(pipeline): report a failed framework pass instead of swallowing it (#1645)

Raghav Chamadiya854aee99b077
diff --git a/packages/cli/src/repowise/cli/commands/dead_code_cmd.py b/packages/cli/src/repowise/cli/commands/dead_code_cmd.py
index 4dadd6f98..1d4f3c8b4 100644
--- a/packages/cli/src/repowise/cli/commands/dead_code_cmd.py
+++ b/packages/cli/src/repowise/cli/commands/dead_code_cmd.py
@@ -183,8 +183,14 @@ def dead_code_command(
tech_items = detect_tech_stack(repo_path)
graph_builder.add_framework_edges([item.name for item in tech_items])
- except Exception:
- pass
+ except Exception as fw_exc:
+ # Silence here is the worst of the three sites: the comment above says
+ # these edges exist to stop false positives, so a swallowed failure
+ # hands the user a longer report and calls it the answer.
+ notices.print(
+ f"[yellow]Framework edge detection skipped: {fw_exc}; "
+ "convention-loaded files may report as unreachable.[/yellow]"
+ )
# Git metadata (best effort)
git_meta_map: dict = {}
diff --git a/packages/core/src/repowise/core/pipeline/incremental.py b/packages/core/src/repowise/core/pipeline/incremental.py
index 912531b2e..a84e2e8ad 100644
--- a/packages/core/src/repowise/core/pipeline/incremental.py
+++ b/packages/core/src/repowise/core/pipeline/incremental.py
@@ -178,6 +178,9 @@ def build_repo_graph(
log(f"[yellow]Skipped {skipped} file(s) that failed to parse.[/yellow]")
# Add framework-aware synthetic edges (conftest, Django, FastAPI, Flask).
+ # Best-effort, but not silent: the update path has to report the failure the
+ # init path reports, or an index degrades differently depending on how it
+ # was built and nothing says which.
try:
from repowise.core.generation.editor_files.tech_stack import detect_tech_stack
@@ -185,8 +188,12 @@ def build_repo_graph(
fw_count = graph_builder.add_framework_edges([item.name for item in tech_items])
if fw_count:
log(f"Framework edges added: [cyan]{fw_count}[/cyan]")
- except Exception:
- pass # framework edge detection is best-effort
+ except Exception as fw_exc:
+ logger.warning("framework_edges_failed", error=str(fw_exc))
+ log(
+ f"[yellow]Framework edge detection skipped: {fw_exc}; framework-invoked "
+ "symbols will have no callers in the graph and may read as dead.[/yellow]"
+ )
# Add dynamic-hint edges, mirroring the init pipeline's ingestion phase.
# Without this the update-built graph was missing every dynamic edge the
diff --git a/packages/core/src/repowise/core/pipeline/phases/ingestion.py b/packages/core/src/repowise/core/pipeline/phases/ingestion.py
index 7617e27b6..6edb93dd9 100644
--- a/packages/core/src/repowise/core/pipeline/phases/ingestion.py
+++ b/packages/core/src/repowise/core/pipeline/phases/ingestion.py
@@ -609,15 +609,34 @@ async def _run_ingestion(
)
await asyncio.to_thread(graph_builder.build, progress)
- # Add framework-aware synthetic edges (conftest, Django, FastAPI, Flask)
+ # Add framework-aware synthetic edges (conftest, Django, FastAPI, Flask).
+ # Two failures with two different costs, reported separately rather than as
+ # one silent pass: the stack also feeds the persisted tech list and the
+ # editor files, so losing it costs more than losing the edges. Keeping the
+ # edge call outside its try is deliberate — the handlers that read no stack
+ # (conftest, gtest, Flutter, Android) still run when detection failed.
tech_items: list = []
try:
from repowise.core.generation.editor_files.tech_stack import detect_tech_stack
tech_items = detect_tech_stack(repo_path)
+ except Exception as tech_exc:
+ logger.warning("tech_stack_detection_failed", error=str(tech_exc))
+ emit_warning(
+ progress,
+ f"Tech stack detection skipped ({tech_exc}); the repo's frameworks will be "
+ "missing from the index, along with every edge that depends on them.",
+ )
+
+ try:
graph_builder.add_framework_edges([item.name for item in tech_items])
- except Exception:
- pass # framework edge detection is best-effort
+ except Exception as fw_exc:
+ logger.warning("framework_edges_failed", error=str(fw_exc))
+ emit_warning(
+ progress,
+ f"Framework edge detection skipped ({fw_exc}); framework-invoked "
+ "symbols will have no callers in the graph and may read as dead.",
+ )
# ---- Dynamic hints wiring (after static graph is fully built) ----------
if progress:
@@ -827,7 +846,12 @@ async def reparse_for_resume(
from repowise.core.generation.editor_files.tech_stack import detect_tech_stack
tech_items = detect_tech_stack(repo_path)
- except Exception:
- pass
+ except Exception as tech_exc:
+ logger.warning("tech_stack_detection_failed", error=str(tech_exc))
+ emit_warning(
+ progress,
+ f"Tech stack detection skipped ({tech_exc}); the repo's frameworks will be "
+ "missing from the index.",
+ )
return parsed_files, file_infos, repo_structure, source_map, tech_items
diff --git a/tests/unit/pipeline/test_framework_edge_failure_visible.py b/tests/unit/pipeline/test_framework_edge_failure_visible.py
new file mode 100644
index 000000000..9c4f7dae5
--- /dev/null
+++ b/tests/unit/pipeline/test_framework_edge_failure_visible.py
@@ -0,0 +1,124 @@
+"""A framework pass that fails must say what it cost, not pass silently.
+
+Both halves of the pass used to sit under one bare ``except Exception: pass``.
+There are 22 framework handlers behind it, so every convention-wired edge in
+the repo could vanish leaving a log-clean run and an index that looks
+complete, and a framework-invoked symbol with no caller reads as dead. The
+two halves also fail differently: losing the tech stack loses the recorded
+frameworks as well as the edges, so each reports its own cost.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+
+import pytest
+
+from repowise.core.pipeline.phases.ingestion import _run_ingestion
+
+
+class _RecordingProgress:
+ """Only the channel a default CLI run renders. See ``emit_warning``."""
+
+ def __init__(self) -> None:
+ self.messages: list[tuple[str, str]] = []
+
+ def on_message(self, level: str, text: str) -> None:
+ self.messages.append((level, text))
+
+ def __getattr__(self, _name: str):
+ return lambda *a, **k: None
+
+ def warnings(self) -> list[str]:
+ return [text for level, text in self.messages if level == "warning"]
+
+
+def _capture_warnings(monkeypatch) -> list[tuple[str, dict]]:
+ """Collect the module logger's warning events and their fields.
+
+ ``caplog`` sees nothing here: the structlog filtering bound logger drops
+ the record before stdlib logging is reached, which is the same reason
+ ``emit_warning`` exists at all. The fields are kept because an event name
+ with no ``error=`` is a log nobody can act on.
+ """
+ from repowise.core.pipeline.phases import ingestion as module
+
+ events: list[tuple[str, dict]] = []
+
+ class _Recorder:
+ def warning(self, event: str, **kw) -> None:
+ events.append((event, kw))
+
+ def __getattr__(self, _name: str):
+ return lambda *a, **k: None
+
+ monkeypatch.setattr(module, "logger", _Recorder())
+ return events
+
+
+def repo(tmp_path: Path) -> Path:
+ (tmp_path / "app.py").write_text("def handler():\n return 1\n", encoding="utf-8")
+ return tmp_path
+
+
+async def _ingest(repo: Path, progress: _RecordingProgress):
+ return await _run_ingestion(
+ repo,
+ exclude_patterns=None,
+ skip_tests=False,
+ skip_infra=False,
+ progress=progress,
+ )
+
+
+async def test_tech_stack_failure_is_logged_and_surfaced(repo, monkeypatch):
+ from repowise.core.generation.editor_files import tech_stack
+
+ def _boom(*_a, **_k):
+ raise RuntimeError("stack probe exploded")
+
+ monkeypatch.setattr(tech_stack, "detect_tech_stack", _boom)
+
+ progress = _RecordingProgress()
+ events = _capture_warnings(monkeypatch)
+ result = await _ingest(repo, progress)
+
+ # Best-effort stays best-effort: the build completes and still parsed the
+ # file, and the tech list downstream consumers read is empty, not unbound.
+ parsed_files, _infos, _structure, _sources, _builder, _stats, tech_items = result
+ assert len(parsed_files) == 1
+ assert tech_items == []
+ assert ("tech_stack_detection_failed", {"error": "stack probe exploded"}) in events
+ assert any("Tech stack detection skipped" in w for w in progress.warnings())
+
+
+async def test_framework_edge_failure_is_logged_and_surfaced(repo, monkeypatch):
+ # Patch the mixin that declares the method, not the class that inherits it,
+ # so teardown does not leave a same-valued shadow behind on GraphBuilder.
+ from repowise.core.ingestion.graph._edges import EdgesMixin
+
+ def _boom(*_a, **_k):
+ raise RuntimeError("handler exploded")
+
+ monkeypatch.setattr(EdgesMixin, "add_framework_edges", _boom)
+
+ progress = _RecordingProgress()
+ events = _capture_warnings(monkeypatch)
+ result = await _ingest(repo, progress)
+
+ assert len(result[0]) == 1
+ assert ("framework_edges_failed", {"error": "handler exploded"}) in events
+ assert any("Framework edge detection skipped" in w for w in progress.warnings())
+
+
+async def test_a_healthy_run_adds_no_framework_warning(repo):
+ progress = _RecordingProgress()
+ result = await _ingest(repo, progress)
+
+ assert result is not None
+ assert not [
+ w
+ for w in progress.warnings()
+ if "Tech stack detection skipped" in w or "Framework edge detection skipped" in w
+ ]