babylon.utils.exceptions
Exception hierarchy for Babylon/Babylon.
Exceptions are contradictions made manifest in code. They represent the system’s failure to reproduce itself.
Error Code Schema: - CFG_XXX: Configuration errors - DB_XXX: Database/persistence errors - EMB_XXX: Embedding/vector errors - VAL_XXX: Validation errors - SYS_XXX: System-level errors - LLM_XXX: LLM generation errors
Exceptions
|
Base exception for all Babylon/Babylon errors. |
|
Raised when configuration is invalid or missing. |
|
Base class for data layer API errors. |
|
Raised when database operations fail. |
|
DEPRECATED: Use RagError instead. |
|
Base class for infrastructure-related errors. |
|
Raised when LLM generation fails. |
alias of |
|
|
Base class for AI/RAG observer layer errors. |
|
Raised when schema validation fails. |
|
Raised when simulation logic fails. |
|
Raised when file/storage operations fail. |
|
Raised when graph/topology operations fail. |
|
Raised when data validation fails. |
- exception babylon.utils.exceptions.BabylonError(message, error_code=None, details=None)[source]
Bases:
ExceptionBase exception for all Babylon/Babylon errors.
All exceptions in the system inherit from this class, allowing for unified error handling at the boundary.
- Parameters:
- Return type:
None
- message
Human-readable error description
- error_code
Machine-readable error identifier
- details
Additional context for debugging
- log(logger, level=logging.ERROR, exc_info=True)[source]
Log this exception with full structured context.
Convenience method for logging exceptions with their structured data included in the log record’s extra fields.
- Parameters:
- Return type:
Example
- try:
risky_operation()
- except BabylonError as e:
e.log(logger) # Logs with ERROR level and full context
- exception babylon.utils.exceptions.InfrastructureError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorBase class for infrastructure-related errors.
These errors are typically retryable and represent external system failures (database, network, filesystem). The simulation can often recover from these.
Error codes: INFRA_XXX
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.StorageError(message, error_code=None, details=None)[source]
Bases:
InfrastructureErrorRaised when file/storage operations fail.
Covers checkpoints, backups, and file I/O.
Error codes: - STOR_001: File not found - STOR_002: File corrupted - STOR_003: Schema validation failed - STOR_004: Write failed
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.ObserverError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorBase class for AI/RAG observer layer errors.
These errors are non-fatal and represent failures in the narrative/observation layer. The simulation can and should continue without the observer.
Error codes: OBS_XXX
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.DataAPIError(status_code, message, url, error_code=None, details=None)[source]
Bases:
InfrastructureErrorBase class for data layer API errors.
These errors represent failures when communicating with external data REST APIs (Census Bureau, FRED, EIA, FCC, etc.). They include HTTP status information and the URL that caused the failure.
Distinct from AI/LLM API errors (Claude, DeepSeek, etc.) which would use different exception classes under ObserverError.
Error codes: DAPI_XXX
- Parameters:
- Return type:
None
- status_code
HTTP status code (0 for connection/timeout errors).
- message
Error message from API or description of failure.
- url
Request URL that caused the error (sensitive params redacted).
- exception babylon.utils.exceptions.DatabaseError(message, error_code=None, details=None)[source]
Bases:
InfrastructureErrorRaised when database operations fail.
The Ledger cannot record the material reality.
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.SchemaError(message, error_code=None, details=None)[source]
Bases:
DatabaseErrorRaised when schema validation fails.
Base class for schema-related errors such as schema drift, missing tables, or incompatible column types.
Error codes: - SCH_001: General schema error - SCH_002: Schema drift detected - SCH_003: Missing table - SCH_004: Incompatible type
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.ValidationError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorRaised when data validation fails.
The input does not conform to the schema of material reality.
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.ConfigurationError(message, error_code=None, details=None)[source]
Bases:
ValidationErrorRaised when configuration is invalid or missing.
The material conditions for operation have not been established.
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.SimulationError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorRaised when simulation logic fails.
The dialectical process has encountered a fatal contradiction.
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.TopologyError(message, error_code=None, details=None)[source]
Bases:
SimulationErrorRaised when graph/topology operations fail.
The relations of production cannot be computed.
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.LLMError(message, error_code=None, details=None)[source]
Bases:
ObserverErrorRaised when LLM generation fails.
The ideological superstructure cannot produce narrative.
Error codes: - LLM_001: General API error - LLM_002: Timeout error - LLM_003: Rate limit exceeded
- Parameters:
- Return type:
None
- exception babylon.utils.exceptions.EmbeddingError(message, error_code=None, details=None)[source]
Bases:
BabylonErrorDEPRECATED: Use RagError instead.
Raised when embedding operations fail. The Archive cannot encode semantic meaning.
- Parameters:
- Return type:
None