Private
Public Access
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.
This commit is contained in:
+34
-8
@@ -7299,6 +7299,29 @@ def _dag_cycle_check_result(app: "App") -> Result[bool]:
|
|||||||
source="gui_2._dag_cycle_check_result",
|
source="gui_2._dag_cycle_check_result",
|
||||||
original=e,
|
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()
|
ed.end()
|
||||||
# 5. Add Ticket Form
|
# 5. Add Ticket Form
|
||||||
@@ -7306,18 +7329,21 @@ def _dag_cycle_check_result(app: "App") -> Result[bool]:
|
|||||||
if imgui.button("Add Ticket"):
|
if imgui.button("Add Ticket"):
|
||||||
app._show_add_ticket_form = not app._show_add_ticket_form
|
app._show_add_ticket_form = not app._show_add_ticket_form
|
||||||
if app._show_add_ticket_form:
|
if app._show_add_ticket_form:
|
||||||
# Default Ticket ID
|
# Default Ticket ID
|
||||||
max_id = 0
|
max_id = 0
|
||||||
for t in app.active_tickets:
|
for t in app.active_tickets:
|
||||||
tid = t.get('id', '')
|
tid = t.get('id', '')
|
||||||
if tid.startswith('T-'):
|
if tid.startswith('T-'):
|
||||||
#TODO(Ed): Exception(Review)
|
parse_result = _ticket_id_max_int_result(tid)
|
||||||
try: max_id = max(max_id, int(tid[2:]))
|
if parse_result.ok:
|
||||||
except: pass
|
max_id = max(max_id, parse_result.data)
|
||||||
app.ui_new_ticket_id = f"T-{max_id + 1:03d}"
|
else:
|
||||||
app.ui_new_ticket_desc = ""
|
if not hasattr(app, '_last_request_errors'): app._last_request_errors = []
|
||||||
app.ui_new_ticket_target = ""
|
app._last_request_errors.append(("render_task_dag_panel.ticket_id_parse", parse_result.errors[0]))
|
||||||
app.ui_new_ticket_deps = ""
|
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:
|
if app._show_add_ticket_form:
|
||||||
imgui.begin_child("add_ticket_form", imgui.ImVec2(-1, 220), True)
|
imgui.begin_child("add_ticket_form", imgui.ImVec2(-1, 220), True)
|
||||||
imgui.text_colored(C_VAL(), "New Ticket Details")
|
imgui.text_colored(C_VAL(), "New Ticket Details")
|
||||||
|
|||||||
@@ -2267,4 +2267,37 @@ def test_phase_10_l7271_dag_cycle_check_result_failure():
|
|||||||
assert "dag engine failure" in err.message
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user