Replace generic errors with custom exceptions in text-generation#25
Replace generic errors with custom exceptions in text-generation#25Kamilbenkirane merged 4 commits intomainfrom
Conversation
- Replace TypeError with ValidationError for missing prompt parameter - Replace ValueError with ConstraintViolationError for invalid thinking_budget - Replace ValueError with ValidationError for empty tool_use input validation - Add imports from celeste.exceptions to all affected files This ensures consistent error handling across the codebase using custom exceptions from exceptions.py instead of generic Python exceptions.
PR Review: Replace generic errors with custom exceptions in text-generationSummaryThis PR successfully replaces generic Python exceptions with custom exceptions from Code Quality ✅Strengths:
Potential Issues
|
Add ValidationError to celeste/__init__.py imports and __all__ list so users can import it directly from celeste instead of celeste.exceptions. This addresses the code review feedback about missing ValidationError from the public API exports.
… ValidationError - Change StreamingNotSupportedError to accept Model object instead of model_id string - Export ValidationError from celeste/__init__.py public API - Replace NotImplementedError with StreamingNotSupportedError in _stream_class and _make_stream_request - Update tests to use Model objects - Use regular import instead of TYPE_CHECKING (no circular dependency) Addresses code review feedback about missing ValidationError export and improves consistency by using Model objects throughout the exception hierarchy.
- Change StreamingNotSupportedError to accept model_id: str instead of Model - Removes circular import dependency (exceptions no longer depend on models) - Updates all usages in client.py to pass model_id=self.model.id - Updates tests to use model_id instead of Model object - Cleaner architecture: exceptions stay low-level and independent
Pull Request Review: Replace generic errors with custom exceptionsSummaryThis PR successfully replaces generic Python exceptions with custom exceptions from ✅ Strengths1. Excellent Exception Hierarchy Design
2. Consistent Error HandlingThe changes improve error granularity across multiple files:
3. Good Architectural Improvements
4. Version BumpAppropriate minor version bump from 0.1.1 → 0.2.0 for API changes 🔍 Areas for Improvement1. Test Coverage Gap
|
Summary
This PR replaces generic Python exceptions (ValueError, TypeError) with appropriate custom exceptions from
celeste.exceptionsin the text-generation package.Changes
TypeErrorwithValidationErrorfor missing prompt parameterValueErrorwithConstraintViolationErrorfor invalid thinking_budgetValueErrorwithValidationErrorfor empty tool_use input dictValueErrorwithValidationErrorfor tool_use validation errorsBenefits
Note
Response parsing errors (missing content in API responses) remain as
ValueErroras they are internal parsing errors, consistent with the core package approach.