Archived Owner: Platform Team
Different modules handle errors inconsistently:
errors.pydefines error categories and custom exceptions with hintsapproval_manager.pyraisesToolPermissionErrordirectly without contextrunner/_core.pycatches broad exception types and re-wraps them
The error handling patterns are not standardized. Some modules use specific error types, others use generic exceptions. Error context and recovery hints are not consistently provided.
We will create a standardized error handling framework with consistent error types, context, and recovery hints.
- Create
ErrorContextclass to capture error metadata (tool name, arguments, state) - Add fields for error classification, severity, and recovery hints
- Add unit tests for error context
- Update error-raising code to use ErrorContext
- Create
ErrorHandlerprotocol/interface for consistent error processing - Implement default error handler with logging and recovery
- Add unit tests for error handling
- Update all modules to use the error handler
- Create factory methods for common error scenarios
- Add methods for tool errors, permission errors, validation errors
- Add unit tests for error factories
- Update all error-raising code to use factories
- Define standard recovery hint categories
- Add recovery hints to all error types
- Create documentation for error handling patterns
- Update error messages to include recovery hints
- Define error severity levels (critical, high, medium, low)
- Add error classification to all error types
- Create error metrics and monitoring
- Update error handling to respect severity
- Maintain backward compatibility during transition
- Add comprehensive tests before refactoring
- Use feature flags to enable new implementation gradually
- Create migration guide for breaking changes
- Positive: Consistent error handling, better debugging, improved recovery
- Negative: Breaking changes to error handling APIs
- Risk: Medium - affects error handling across all modules
- Keep inconsistent error handling (rejected - technical debt)
- Use third-party error handling library (rejected - adds dependency)
- Use exception hierarchy only (rejected - missing context)
- Original issue: Medium-severity architecture issue #5
- Related files:
errors.py,approval_manager.py,runner/_core.py