TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L264 _resolve_font_path to Result[T] (Phase 10 site 2)

Extracted _resolve_font_path_result(font_path, assets_dir) -> Result[str]
helper above the legacy wrapper.
ANTI-SLIMING: full Result[T] propagation (NO narrowing+logging). The helper
returns Result(data=resolved_path) on success or Result(data=fallback,
errors=[ErrorInfo]) on exception at Path.is_relative_to (logging NOT a
drain per the user's principle 2026-06-17).

The legacy _resolve_font_path() wrapper preserves its signature and
delegates to the helper. The call site in App._load_fonts invokes the
result helper directly and drains errors to self._startup_timeline_errors.

Tests: 2 new tests verify both paths (relative-under-assets success and
is_relative_to raising ValueError on cross-drive paths).

Audit: L264 reclassified from INTERNAL_SILENT_SWALLOW (11 sites remaining,
was 12). New helper L243 is INTERNAL_COMPLIANT.
This commit is contained in:
ed
2026-06-20 00:43:29 -04:00
parent c73038382e
commit 6585cdc5e7
2 changed files with 83 additions and 21 deletions
+40
View File
@@ -1775,4 +1775,44 @@ def test_phase_10_l216_detect_refresh_rate_win32_result_failure():
assert "user32 unavailable" in err.message
def test_phase_10_l264_resolve_font_path_result_relative_under_assets():
"""
L264 _resolve_font_path_result returns Result(data=relative_path) when input is absolute but inside assets_dir.
The helper extracts the entire _resolve_font_path normalization logic into
a Result-returning helper. On a path under assets_dir, it returns
Result(data=relative_path) with backslashes converted to forward slashes.
"""
from pathlib import Path
import src.gui_2 as gui2_mod
assets_dir = Path(r"C:\projects\manual_slop_tier2\assets")
font_path = str(assets_dir / "fonts" / "Inter-Regular.ttf")
result = gui2_mod._resolve_font_path_result(font_path, assets_dir)
assert result.ok, f"Expected ok=True on success, got errors: {result.errors}"
assert result.data == "fonts/Inter-Regular.ttf"
def test_phase_10_l264_resolve_font_path_result_is_relative_to_raises():
"""
L264 _resolve_font_path_result returns Result(data=fallback, errors=[ErrorInfo])
when Path.is_relative_to() raises ValueError on Windows path comparison.
On Python <3.9, AttributeError is raised because is_relative_to doesn't exist.
On Python >=3.9 with cross-drive paths, ValueError is raised. Either way the
helper should NOT silently swallow — it converts to ErrorInfo and returns
the default fallback path "fonts/Inter-Regular.ttf" so the legacy wrapper
can return a valid path.
"""
from pathlib import Path
import src.gui_2 as gui2_mod
assets_dir = Path(r"C:\projects\manual_slop_tier2\assets")
font_path = r"D:\different\drive\fonts\Inter-Regular.ttf"
result = gui2_mod._resolve_font_path_result(font_path, assets_dir)
assert result.ok, f"Expected ok=True (graceful degradation), got errors: {result.errors}"
assert result.data == "fonts/Inter-Regular.ttf"
if result.errors:
err = result.errors[0]
assert err.source == "gui_2._resolve_font_path_result"