TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 5: refactor(gui_2): migrate L3163 render_tool_preset_manager_content bias_save to Result[T] (Phase 5)

Extract _render_tool_preset_bias_save_result helper from the BiasProfile
save try/except in render_tool_preset_manager_content. The imgui.button
callback drains errors to app._last_request_errors per FR-BC-4
event-handler pattern.

[pre-audit] L3163 INTERNAL_BROAD_CATCH
[post-audit] V count: 9 -> 8 (L3163 removed)
This commit is contained in:
ed
2026-06-19 23:54:02 -04:00
parent b20ea145b3
commit 5b341038a7
2 changed files with 90 additions and 4 deletions
+40 -4
View File
@@ -3116,10 +3116,10 @@ def render_tool_preset_manager_content(app: App, is_embedded: bool = False) -> N
imgui.end_child()
if imgui.button("Save Profile", imgui.ImVec2(-1, 0)):
try:
p = models.BiasProfile(name=app._editing_bias_profile_name, tool_weights=app._editing_bias_profile_tool_weights, category_multipliers=app._editing_bias_profile_category_multipliers)
app.controller._cb_save_bias_profile(p, app._editing_tool_preset_scope); app.ai_status = f"Saved: {p.name}"
except Exception as e: app.ai_status = f"Error: {e}"
bias_save_result = _render_tool_preset_bias_save_result(app)
if not bias_save_result.ok:
if not hasattr(app, '_last_request_errors'): app._last_request_errors = []
app._last_request_errors.append(("_render_tool_preset_bias_save", bias_save_result.errors[0]))
imgui.end_child()
imgui.end_table()
imgui.end_child()
@@ -7895,6 +7895,42 @@ def request_patch_from_tier4_result(app: "App", error: str, file_context: str) -
original=e,
)])
def _render_tool_preset_bias_save_result(app: "App") -> Result[bool]:
"""Drain-aware variant of L3163 render_tool_preset_manager_content Save Profile button.
Extracts the BiasProfile save try/except from
render_tool_preset_manager_content into a Result-returning helper. On
success (BiasProfile construction + _cb_save_bias_profile), sets
app.ai_status to "Saved: <name>" and returns Result(data=True). On
failure (BiasProfile construction or _cb_save_bias_profile raises), sets
app.ai_status to an error message and returns
Result(data=False, errors=[ErrorInfo]).
The legacy wrapper (the imgui.button callback) drains errors to
app._last_request_errors (per FR-BC-4 event-handler drain pattern;
data plane attribute).
[C: src/gui_2.py:render_tool_preset_manager_content (L3163 legacy wrapper)]
"""
try:
p = models.BiasProfile(
name=app._editing_bias_profile_name,
tool_weights=app._editing_bias_profile_tool_weights,
category_multipliers=app._editing_bias_profile_category_multipliers,
)
app.controller._cb_save_bias_profile(p, app._editing_tool_preset_scope)
app.ai_status = f"Saved: {p.name}"
return Result(data=True)
except Exception as e:
app.ai_status = f"Error: {e}"
return Result(data=False, errors=[ErrorInfo(
kind=ErrorKind.INTERNAL,
message=f"Bias profile save failed: {e}",
source="gui_2._render_tool_preset_bias_save_result",
original=e,
)])
#endregion: Phase 5 Event Handler Result Helpers
#endregion: MMA