From 3c752eb2aed30e82e2259dd78752f32550c64f8c Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 01:03:15 -0400 Subject: [PATCH] TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 10: refactor(gui_2): migrate L7315 render_task_dag_panel ticket_id_parse to Result[T] (Phase 10 site 13) Extracted _ticket_id_max_int_result(tid) -> Result[int] helper above the call site in render_task_dag_panel. ANTI-SLIMING: full Result[T] propagation (NO bare-except+pass). The helper returns Result(data=int) on success or Result(data=0, errors=[ErrorInfo]) on parse failure (logging NOT a drain per the user's principle 2026-06-17). The legacy render_task_dag_panel code preserves the max_id computation, calls the helper, and drains errors to app._last_request_errors. Tests: 2 new tests verify both paths (success on 'T-042' and parse failure on 'T-abc'). Audit: L7315 reclassified from INTERNAL_SILENT_SWALLOW (0 sites remaining, was 1). New helper L7315 is INTERNAL_COMPLIANT. --- src/gui_2.py | 42 ++++++++++++++++++++++++++++++-------- tests/test_gui_2_result.py | 33 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/gui_2.py b/src/gui_2.py index 16f476e9..9562bb89 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -7299,6 +7299,29 @@ def _dag_cycle_check_result(app: "App") -> Result[bool]: source="gui_2._dag_cycle_check_result", original=e, )]) + +def _ticket_id_max_int_result(tid: str) -> Result[int]: + """Drain-aware variant of render_task_dag_panel ticket-ID parsing (L7315 INTERNAL_SILENT_SWALLOW). + + Extracts the bare-except int(tid[2:]) parse from the ticket-ID loop in + render_task_dag_panel into a Result-returning helper. On success (valid + T-XXX id), returns Result(data=int). On failure (T-abc, T-, etc.), + returns Result(data=0, errors=[ErrorInfo]). The legacy loop skips + malformed tickets via the data plane (logging NOT a drain per the + user's principle 2026-06-17). The caller drains to + app._last_request_errors. + + [C: src/gui_2.py:render_task_dag_panel (L7315 caller)] + """ + try: + return Result(data=int(tid[2:])) + except Exception as e: + return Result(data=0, errors=[ErrorInfo( + kind=ErrorKind.INTERNAL, + message=f"ticket id parse failed for {tid!r}: {e}", + source="gui_2._ticket_id_max_int_result", + original=e, + )]) ed.end() # 5. Add Ticket Form @@ -7306,18 +7329,21 @@ def _dag_cycle_check_result(app: "App") -> Result[bool]: if imgui.button("Add Ticket"): app._show_add_ticket_form = not app._show_add_ticket_form if app._show_add_ticket_form: - # Default Ticket ID + # Default Ticket ID max_id = 0 for t in app.active_tickets: tid = t.get('id', '') if tid.startswith('T-'): - #TODO(Ed): Exception(Review) - try: max_id = max(max_id, int(tid[2:])) - except: pass - app.ui_new_ticket_id = f"T-{max_id + 1:03d}" - app.ui_new_ticket_desc = "" - app.ui_new_ticket_target = "" - app.ui_new_ticket_deps = "" + parse_result = _ticket_id_max_int_result(tid) + if parse_result.ok: + max_id = max(max_id, parse_result.data) + else: + if not hasattr(app, '_last_request_errors'): app._last_request_errors = [] + app._last_request_errors.append(("render_task_dag_panel.ticket_id_parse", parse_result.errors[0])) + app.ui_new_ticket_id = f"T-{max_id + 1:03d}" + app.ui_new_ticket_desc = "" + app.ui_new_ticket_target = "" + app.ui_new_ticket_deps = "" if app._show_add_ticket_form: imgui.begin_child("add_ticket_form", imgui.ImVec2(-1, 220), True) imgui.text_colored(C_VAL(), "New Ticket Details") diff --git a/tests/test_gui_2_result.py b/tests/test_gui_2_result.py index a30297d3..c1c031ef 100644 --- a/tests/test_gui_2_result.py +++ b/tests/test_gui_2_result.py @@ -2267,4 +2267,37 @@ def test_phase_10_l7271_dag_cycle_check_result_failure(): assert "dag engine failure" in err.message +def test_phase_10_l7315_ticket_id_max_int_result_success(): + """ + L7315 _ticket_id_max_int_result returns Result(data=int) on success. + + The helper extracts the int(tid[2:]) parsing from the ticket-ID loop + in render_task_dag_panel into a Result-returning helper. On success + (valid T-XXX id), returns Result(data=int). The legacy loop continues + with the maximum value. + """ + import src.gui_2 as gui2_mod + result = gui2_mod._ticket_id_max_int_result("T-042") + assert result.ok, f"Expected ok=True on success, got errors: {result.errors}" + assert result.data == 42 + + +def test_phase_10_l7315_ticket_id_max_int_result_failure(): + """ + L7315 _ticket_id_max_int_result returns Result(data=0, errors=[ErrorInfo]) on failure. + + When tid[2:] is not parseable as int (e.g., "T-abc", "T-"), the helper + converts to ErrorInfo. The legacy loop skips this ticket and continues + with the current max. The caller drains to app._last_request_errors. + """ + import src.gui_2 as gui2_mod + result = gui2_mod._ticket_id_max_int_result("T-abc") + assert not result.ok, f"Expected ok=False on failure, got data: {result.data}" + assert result.data == 0 + assert result.errors, "Expected at least one error on failure" + err = result.errors[0] + assert err.source == "gui_2._ticket_id_max_int_result" + assert "invalid literal" in err.message or "T-abc" in err.message + +