Private
Public Access
TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L216 _detect_refresh_rate_win32 to Result[T] (Phase 10 site 1)
Extracted _detect_refresh_rate_win32_result() helper above the legacy wrapper. ANTI-SLIMING: full Result[T] propagation (NO narrowing+logging). The helper returns Result(data=rate) on success or Result(data=0.0, errors=[ErrorInfo]) on exception (logging NOT a drain per the user's principle 2026-06-17). The legacy _detect_refresh_rate_win32() wrapper preserves its signature and delegates to the helper. The call site in App.__init__ invokes the result helper directly and drains errors to self._startup_timeline_errors. Tests: 2 new tests (test_phase_10_l216_detect_refresh_rate_win32_result_success, test_phase_10_l216_detect_refresh_rate_win32_result_failure) verify both paths. Audit: L216 reclassified from INTERNAL_SILENT_SWALLOW (12 sites remaining, was 13). New helper L219 is INTERNAL_COMPLIANT.
This commit is contained in:
+34
-11
@@ -178,13 +178,16 @@ def truncate_entries(entries: list[dict[str, Any]], max_pairs: int) -> list[dict
|
||||
if count == target: return entries[i:]
|
||||
return entries
|
||||
|
||||
def _detect_refresh_rate_win32() -> float:
|
||||
"""Return the primary display's current refresh rate in Hz, or 0.0 on failure.
|
||||
def _detect_refresh_rate_win32_result() -> Result[float]:
|
||||
"""Drain-aware variant of _detect_refresh_rate_win32 (L216 INTERNAL_SILENT_SWALLOW).
|
||||
|
||||
Uses user32.EnumDisplaySettingsW (ENUM_CURRENT_SETTINGS) which reads the value
|
||||
directly from the display driver in microseconds. The previous implementation
|
||||
shelled out to PowerShell + WMI (Get-CimInstance Win32_VideoController), which
|
||||
cost ~350ms on every startup and blocked the first frame.
|
||||
Extracts the thirdparty ctypes user32.EnumDisplaySettingsW try/except from
|
||||
_detect_refresh_rate_win32 into a Result-returning helper. On exception,
|
||||
returns Result(data=0.0, errors=[ErrorInfo]) so the legacy wrapper can
|
||||
fall back to the safe 0.0 default. On success, returns Result(data=rate)
|
||||
where rate is the detected display frequency in Hz.
|
||||
|
||||
[C: src/gui_2.py:_detect_refresh_rate_win32 (L216 legacy wrapper)]
|
||||
"""
|
||||
#Note(Ed): Exception(Thirdparty)
|
||||
try:
|
||||
@@ -210,12 +213,32 @@ def _detect_refresh_rate_win32() -> float:
|
||||
dm = _DEVMODE()
|
||||
dm.dmSize = ctypes.sizeof(_DEVMODE)
|
||||
if ctypes.windll.user32.EnumDisplaySettingsW(None, -1, ctypes.byref(dm)):
|
||||
# dmDisplayFrequency is 0 or 1 for "default/hardware" on some drivers.
|
||||
if dm.dmDisplayFrequency > 1:
|
||||
return float(dm.dmDisplayFrequency)
|
||||
except Exception:
|
||||
pass
|
||||
return 0.0
|
||||
return Result(data=float(dm.dmDisplayFrequency))
|
||||
return Result(data=0.0)
|
||||
except Exception as e:
|
||||
return Result(data=0.0, errors=[ErrorInfo(
|
||||
kind=ErrorKind.INTERNAL,
|
||||
message=f"win32 EnumDisplaySettingsW failed: {e}",
|
||||
source="gui_2._detect_refresh_rate_win32_result",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
def _detect_refresh_rate_win32() -> float:
|
||||
"""Return the primary display's current refresh rate in Hz, or 0.0 on failure.
|
||||
|
||||
Uses user32.EnumDisplaySettingsW (ENUM_CURRENT_SETTINGS) which reads the value
|
||||
directly from the display driver in microseconds. The previous implementation
|
||||
shelled out to PowerShell + WMI (Get-CimInstance Win32_VideoController), which
|
||||
cost ~350ms on every startup and blocked the first frame.
|
||||
|
||||
Legacy wrapper: delegates to _detect_refresh_rate_win32_result. Preserves
|
||||
the original signature (returns float). The call site in App.__init__
|
||||
invokes the result helper directly and drains errors to
|
||||
self._startup_timeline_errors.
|
||||
"""
|
||||
result = _detect_refresh_rate_win32_result()
|
||||
return result.data
|
||||
|
||||
def _resolve_font_path(font_path: str, assets_dir: Path) -> str:
|
||||
"""Normalize a configured font path to something hello_imgui can load.
|
||||
|
||||
Reference in New Issue
Block a user