Spaces:
Runtime error
Runtime error
Download voice_control/exceptions.py from nifty-coder/stemsplit-backend: direct link, hf CLI and curl.
- Browser
- Download file 6.72 kB
-
https://huggingface.co/spaces/nifty-coder/stemsplit-backend/resolve/main/voice_control/exceptions.py
- Command line
-
hf download hf://spaces/nifty-coder/stemsplit-backend/voice_control/exceptions.py
-
curl -L -o exceptions.py https://huggingface.co/spaces/nifty-coder/stemsplit-backend/resolve/main/voice_control/exceptions.py
6.72 kB
| """ | |
| Custom exceptions for the voice control optimization system. | |
| This module defines all custom exceptions used throughout the voice control | |
| system to provide clear error handling and debugging information. | |
| """ | |
| class VoiceControlError(Exception): | |
| """Base exception for all voice control system errors.""" | |
| def __init__(self, message: str, error_code: str = None, details: dict = None): | |
| super().__init__(message) | |
| self.message = message | |
| self.error_code = error_code or self.__class__.__name__ | |
| self.details = details or {} | |
| class ProviderError(VoiceControlError): | |
| """Base exception for STT provider errors.""" | |
| def __init__(self, provider: str, message: str, error_code: str = None, details: dict = None): | |
| super().__init__(message, error_code, details) | |
| self.provider = provider | |
| class ProviderUnavailableError(ProviderError): | |
| """Raised when a provider is unavailable or unhealthy.""" | |
| pass | |
| class ProviderTimeoutError(ProviderError): | |
| """Raised when a provider request times out.""" | |
| pass | |
| class ProviderAuthenticationError(ProviderError): | |
| """Raised when provider authentication fails.""" | |
| pass | |
| class QuotaExceededError(ProviderError): | |
| """Raised when provider quota limits are exceeded.""" | |
| def __init__(self, provider: str, quota_type: str, current_usage: float, limit: float): | |
| message = f"Quota exceeded for {provider}: {quota_type} usage {current_usage} >= limit {limit}" | |
| super().__init__(provider, message) | |
| self.quota_type = quota_type | |
| self.current_usage = current_usage | |
| self.limit = limit | |
| class RateLimitExceededError(ProviderError): | |
| """Raised when provider rate limits are exceeded.""" | |
| def __init__(self, provider: str, quota_type: str = None, retry_after: float = None): | |
| message = f"Rate limit exceeded for {provider}" | |
| if quota_type: | |
| message += f" ({quota_type})" | |
| if retry_after: | |
| message += f", retry after {retry_after:.1f} seconds" | |
| super().__init__(provider, message) | |
| self.quota_type = quota_type | |
| self.retry_after = retry_after | |
| class UnsupportedFormatError(ProviderError): | |
| """Raised when a provider doesn't support the requested audio format.""" | |
| def __init__(self, provider: str, format: str, supported_formats: list = None): | |
| message = f"Provider {provider} does not support format '{format}'" | |
| if supported_formats: | |
| message += f", supported formats: {', '.join(supported_formats)}" | |
| super().__init__(provider, message) | |
| self.format = format | |
| self.supported_formats = supported_formats or [] | |
| class UnsupportedLanguageError(ProviderError): | |
| """Raised when a provider doesn't support the requested language.""" | |
| def __init__(self, provider: str, language: str, supported_languages: list = None): | |
| message = f"Provider {provider} does not support language '{language}'" | |
| if supported_languages: | |
| message += f", supported languages: {', '.join(supported_languages)}" | |
| super().__init__(provider, message) | |
| self.language = language | |
| self.supported_languages = supported_languages or [] | |
| class AudioProcessingError(VoiceControlError): | |
| """Raised when audio processing operations fail.""" | |
| def __init__(self, operation: str, message: str, details: dict = None): | |
| super().__init__(f"Audio processing failed during {operation}: {message}", details=details) | |
| self.operation = operation | |
| class AudioFormatError(AudioProcessingError): | |
| """Raised when audio format conversion fails.""" | |
| def __init__(self, source_format: str, target_format: str, message: str): | |
| super().__init__( | |
| "format_conversion", | |
| f"Failed to convert from {source_format} to {target_format}: {message}" | |
| ) | |
| self.source_format = source_format | |
| self.target_format = target_format | |
| class CacheError(VoiceControlError): | |
| """Base exception for cache-related errors.""" | |
| pass | |
| class CacheKeyError(CacheError): | |
| """Raised when cache key generation fails.""" | |
| pass | |
| class CacheStorageError(CacheError): | |
| """Raised when cache storage operations fail.""" | |
| pass | |
| class ConfigurationError(VoiceControlError): | |
| """Raised when configuration is invalid or missing.""" | |
| def __init__(self, config_key: str, message: str, details: dict = None): | |
| super().__init__(f"Configuration error for '{config_key}': {message}", details=details) | |
| self.config_key = config_key | |
| class ValidationError(VoiceControlError): | |
| """Raised when data validation fails.""" | |
| def __init__(self, field: str, value: any, message: str): | |
| super().__init__(f"Validation failed for field '{field}' with value '{value}': {message}") | |
| self.field = field | |
| self.value = value | |
| class CircuitBreakerError(ProviderError): | |
| """Raised when a provider's circuit breaker is open.""" | |
| def __init__(self, provider: str, failure_count: int, threshold: int): | |
| message = f"Circuit breaker open for {provider}: {failure_count} failures >= {threshold} threshold" | |
| super().__init__(provider, message) | |
| self.failure_count = failure_count | |
| self.threshold = threshold | |
| class NoProvidersAvailableError(VoiceControlError): | |
| """Raised when no providers are available for transcription.""" | |
| def __init__(self, attempted_providers: list = None): | |
| message = "No providers available for transcription" | |
| if attempted_providers: | |
| message += f", attempted: {', '.join(attempted_providers)}" | |
| super().__init__(message) | |
| self.attempted_providers = attempted_providers or [] | |
| class TranscriptionError(VoiceControlError): | |
| """Raised when transcription fails for non-provider-specific reasons.""" | |
| def __init__(self, message: str, confidence: float = None, partial_result: str = None): | |
| super().__init__(message) | |
| self.confidence = confidence | |
| self.partial_result = partial_result | |
| class CostMonitoringError(VoiceControlError): | |
| """Raised when cost monitoring operations fail.""" | |
| pass | |
| class BudgetExceededError(CostMonitoringError): | |
| """Raised when budget thresholds are exceeded.""" | |
| def __init__(self, provider: str, current_cost: float, threshold: float, time_period: str): | |
| message = f"Budget exceeded for {provider}: ${current_cost:.2f} >= ${threshold:.2f} for {time_period}" | |
| super().__init__(message) | |
| self.provider = provider | |
| self.current_cost = current_cost | |
| self.threshold = threshold | |
| self.time_period = time_period |