Private
Public Access
refactor(app_controller): migrate 5 callback sites to Result (batch 1)
Migrated 5 INTERNAL_BROAD_CATCH sites to the data-oriented Result[T] pattern:
1. _handle_custom_callback (L537)
- Narrowed: except Exception -> except (TypeError, ValueError, AttributeError, KeyError, IndexError, RuntimeError, OSError)
- Returns Result[None] via OK on success, Result(data=None, errors=[...]) on failure
- logging.debug added per Heuristic #19
2. _handle_click (L579)
- Narrowed: except Exception -> except (TypeError, ValueError, AttributeError, KeyError, IndexError, RuntimeError)
- Preserves the no-arg fallback (func()) behavior
- Returns Result[None] on success/failure
3. cb_load_prior_log inner (L2046) - bare except in json.dumps
- Narrowed: bare except -> except (TypeError, ValueError)
- Added logging.debug for tool_calls serialization failure
- Preserves the [TOOL CALLS PRESENT] fallback
4. cb_load_prior_log inner (L2068) - bare except in datetime parsing
- Narrowed: bare except -> except (ValueError, TypeError, KeyError, IndexError)
- Added logging.debug for first_ts parse failure
- Preserves the time.time() fallback
5. cb_load_prior_log outer (L2081) - except Exception
- Narrowed: except Exception -> except (OSError, IOError, json.JSONDecodeError, ValueError, TypeError, KeyError, AttributeError)
- Returns Result[None] with ErrorInfo; preserves the ai_status set + early return
- State mutations after the try block are still skipped on error (same as before)
Test impact: 5 new test_app_controller_result tests verify the contract.
tier-1-unit-core: 885 passed (was 883, +2 from earlier Phase 1); 1 expected
failure (test_app_controller_does_not_use_broad_except) will pass after
all 32 sites are migrated across Phases 2-4.
Refs: spec.md FR1, plan.md Task 2.2
Refs: 26e57577 (Phase 1 regression fix on the same file)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import json
|
||||
import subprocess
|
||||
r = subprocess.run(['uv', 'run', 'python', 'scripts/audit_exception_handling.py', '--json'], capture_output=True, text=True)
|
||||
data = json.loads(r.stdout)
|
||||
app = [f for f in data['files'] if 'app_controller' in f.get('filename', '')][0]
|
||||
findings = app['findings']
|
||||
broad = [f for f in findings if f.get('category') == 'INTERNAL_BROAD_CATCH']
|
||||
# Batch 1: L539, L581, L2048, L2070, L2083
|
||||
for line_num in [539, 581, 2048, 2070, 2083]:
|
||||
matches = [f for f in broad if f.get('line') == line_num]
|
||||
if matches:
|
||||
f = matches[0]
|
||||
ctx = f.get('context', '')
|
||||
print(f'=== L{line_num} (category: {f.get("category", "")}, kind: {f.get("kind", "")}) ===')
|
||||
print(f' context: {ctx[:300]}')
|
||||
print()
|
||||
Reference in New Issue
Block a user