implement custom exceptions for Celeste and add unit tests#23
Merged
Kamilbenkirane merged 8 commits intowithceleste:mainfrom Nov 9, 2025
Merged
implement custom exceptions for Celeste and add unit tests#23Kamilbenkirane merged 8 commits intowithceleste:mainfrom
Kamilbenkirane merged 8 commits intowithceleste:mainfrom
Conversation
- Update test_init.py to expect ModelNotFoundError instead of ValueError - Update test_credentials.py to expect MissingCredentialsError instead of ValueError - Update test_client.py to expect ClientNotFoundError instead of NotImplementedError - Update test_exceptions.py to use kebab-case capability strings (text-generation, image-generation, etc.)
Following the pattern of Client (not CelesteClient) and Parameter (not CelesteParameter), the base exception is now Error (not CelesteError) for consistency.
Move exception imports from inside test functions to top of file for proper Python import ordering.
…xports - Replace all ValueError/TypeError in constraints.py with ConstraintViolationError - Remove base exception classes from __all__ exports (keep for inheritance) - Update all constraint tests to expect ConstraintViolationError - Add ConstraintViolationError tests to test_exceptions.py This makes constraint violations catchable as a specific exception type while keeping the API surface minimal by not exporting base classes.
…rings - Make ModelNotFoundError support optional parameters (model_id, provider, capability) - Update _resolve_model to use ModelNotFoundError instead of ValueError for no models available - Add UnsupportedCapabilityError to create_client docstring Raises section - Update Client.stream() docstring to mention StreamingNotSupportedError - Update tests to expect correct custom exceptions instead of generic ones
- Remove .value attribute access from StrEnum instances (Capability, Provider, Parameter) - StrEnum instances can be used directly as strings - Updated all exception calls to pass StrEnum directly instead of .value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improved Exception Handling and Type Safety
Summary
This PR enhances the Celeste library's error handling with a comprehensive custom exception hierarchy and adds robust input validation across core modules.
Changes Made
1. New Exception Classes (
exceptions.py)Added domain-specific exceptions for better error handling:
ValidationError- For parameter and constraint validation failuresConfigurationError- For invalid configuration or setup issuesNetworkError- For HTTP/network-related failuresProviderError- For provider-specific API errorsRateLimitError- For rate limiting and quota issuesModelError- For model-related errorsAll exceptions include:
detailsdict for debuggingfromclause2. Updated Modules with Custom Exceptions
constraints.pyValueError/TypeErrorwithValidationErrorparameters.pyValidationErrorfor constraint violationsmodels.pyConfigurationErrorfor display name mismatchesValidationErrorfor capability/constraint issuescredentials.pyMissingCredentialsErrormessagesclient.pyNetworkErrorfor HTTP failuresProviderErrorfor API errors with response detailsConfigurationErrorfor client setup issueshttp.pyNetworkErrorfor connection/timeout failures3. Input Validation
Added validation to prevent runtime errors:
parameters.py: Validates mapper name isStrEnummodels.py: Validates model registration inputshttp.py: Validates timeout and connection limits4. Comprehensive Tests
New test file
tests/unit_tests/test_exceptions_enhanced.pywith:Benefits
✅ Better Developer Experience: Clear, actionable error messages
✅ Easier Debugging: Detailed context in exception details
✅ Type Safety: All exceptions properly typed and documented
✅ Backward Compatible: Extends existing exceptions without breaking changes
✅ Testable: Custom exceptions can be caught and asserted specifically
✅ Production Ready: Proper logging and error tracking support