Spaces:
Sleeping
Sleeping
File size: 7,120 Bytes
b9f4b13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | """
VentureForge Custom Exceptions
===============================
Domain-specific exceptions for better error handling and debugging.
"""
from __future__ import annotations
from typing import Any
class VentureForgeError(Exception):
"""Base exception for all VentureForge errors."""
pass
# =============================================================================
# PIPELINE ERRORS
# =============================================================================
class PipelineError(VentureForgeError):
"""Base class for pipeline execution errors."""
pass
class PipelineStageError(PipelineError):
"""Error during a specific pipeline stage."""
def __init__(self, stage: str, message: str):
self.stage = stage
super().__init__(f"[{stage}] {message}")
class MaxAttemptsExceededError(PipelineError):
"""Maximum retry attempts exceeded."""
def __init__(self, operation: str, max_attempts: int):
self.operation = operation
self.max_attempts = max_attempts
super().__init__(f"{operation} failed after {max_attempts} attempts")
# =============================================================================
# DATA VALIDATION ERRORS
# =============================================================================
class ValidationError(VentureForgeError):
"""Base class for data validation errors."""
pass
class InvalidPainPointError(ValidationError):
"""Pain point failed validation checks."""
def __init__(self, reason: str, pain_point_id: str | None = None):
self.reason = reason
self.pain_point_id = pain_point_id
msg = "Invalid pain point"
if pain_point_id:
msg += f" (ID: {pain_point_id})"
msg += f": {reason}"
super().__init__(msg)
class InvalidIdeaError(ValidationError):
"""Idea failed validation checks."""
def __init__(self, reason: str, idea_id: str | None = None):
self.reason = reason
self.idea_id = idea_id
msg = "Invalid idea"
if idea_id:
msg += f" (ID: {idea_id})"
msg += f": {reason}"
super().__init__(msg)
class InvalidPitchError(ValidationError):
"""Pitch brief failed validation checks."""
def __init__(self, reason: str, pitch_id: str | None = None):
self.reason = reason
self.pitch_id = pitch_id
msg = "Invalid pitch"
if pitch_id:
msg += f" (ID: {pitch_id})"
msg += f": {reason}"
super().__init__(msg)
class MissingRequiredFieldError(ValidationError):
"""Required field is missing from data structure."""
def __init__(self, field_name: str, model_name: str):
self.field_name = field_name
self.model_name = model_name
super().__init__(f"Required field '{field_name}' missing from {model_name}")
# =============================================================================
# LLM ERRORS
# =============================================================================
class LLMError(VentureForgeError):
"""Base class for LLM-related errors."""
pass
class LLMTimeoutError(LLMError):
"""LLM request timed out."""
def __init__(self, timeout_seconds: int):
self.timeout_seconds = timeout_seconds
super().__init__(f"LLM request timed out after {timeout_seconds} seconds")
class LLMInvalidResponseError(LLMError):
"""LLM returned invalid or unparseable response."""
def __init__(self, expected_format: str, received: str):
self.expected_format = expected_format
self.received = received
super().__init__(f"Expected {expected_format}, received: {received[:200]}")
class LLMJSONParseError(LLMError):
"""Failed to parse JSON from LLM response."""
def __init__(self, raw_response: str, parse_error: str):
self.raw_response = raw_response
self.parse_error = parse_error
super().__init__(f"JSON parse error: {parse_error}. Response: {raw_response[:200]}")
class LLMRateLimitError(LLMError):
"""LLM API rate limit exceeded."""
def __init__(self, retry_after: int | None = None):
self.retry_after = retry_after
msg = "LLM API rate limit exceeded"
if retry_after:
msg += f". Retry after {retry_after} seconds"
super().__init__(msg)
# =============================================================================
# SCRAPING ERRORS
# =============================================================================
class ScrapingError(VentureForgeError):
"""Base class for web scraping errors."""
pass
class NoDataFoundError(ScrapingError):
"""No data found from scraping source."""
def __init__(self, source: str, domain: str):
self.source = source
self.domain = domain
super().__init__(f"No data found from {source} for domain '{domain}'")
class ScraperAPIError(ScrapingError):
"""External scraping API returned an error."""
def __init__(self, api_name: str, status_code: int, message: str):
self.api_name = api_name
self.status_code = status_code
self.message = message
super().__init__(f"{api_name} API error (HTTP {status_code}): {message}")
# =============================================================================
# CONFIGURATION ERRORS
# =============================================================================
class ConfigurationError(VentureForgeError):
"""Base class for configuration errors."""
pass
class MissingAPIKeyError(ConfigurationError):
"""Required API key is missing."""
def __init__(self, key_name: str):
self.key_name = key_name
super().__init__(
f"Missing required API key: {key_name}. Set it in .env or environment variables."
)
class InvalidConfigurationError(ConfigurationError):
"""Configuration value is invalid."""
def __init__(self, setting_name: str, value: Any, reason: str):
self.setting_name = setting_name
self.value = value
self.reason = reason
super().__init__(f"Invalid configuration for '{setting_name}' = {value}: {reason}")
# =============================================================================
# STATE MANAGEMENT ERRORS
# =============================================================================
class StateError(VentureForgeError):
"""Base class for state management errors."""
pass
class InvalidStateTransitionError(StateError):
"""Attempted invalid state transition."""
def __init__(self, from_stage: str, to_stage: str, reason: str):
self.from_stage = from_stage
self.to_stage = to_stage
self.reason = reason
super().__init__(f"Invalid transition from {from_stage} to {to_stage}: {reason}")
class StateCorruptionError(StateError):
"""State data is corrupted or inconsistent."""
def __init__(self, field_name: str, reason: str):
self.field_name = field_name
self.reason = reason
super().__init__(f"State corruption detected in '{field_name}': {reason}")
|