Source code for kaxanuk.attribution_analysis.exceptions

"""
Hierarchical exception system for the attribution analysis engine.

This module provides a structured exception hierarchy following the clean,
layered error-handling architecture. Exceptions are designed to be:

- **Simple**: Plain exception classes without unnecessary complexity
- **Self-descriptive**: Exception names clearly indicate the error domain
- **Chainable**: Support for exception chaining via ``raise ... from error``
- **Groupable**: ExceptionGroup support for aggregating multiple related errors
- **Compatible**: the errors that replaced a bare ``ValueError`` or ``TypeError`` also
  subclass it, so ``except ValueError`` / ``except TypeError`` callers keep working

Exception Hierarchy
-------------------
::

    AttributionAnalysisError (base for recoverable errors)
    ├── ConfigurationError
    │   ├── ConfigurationHandlerError
    │   ├── InjectedDependencyError
    │   └── AttributionArgumentError (also ValueError)
    ├── DataError
    │   ├── DataLoadingError
    │   │   ├── MissingCSVReadError
    │   │   ├── ReadingCSVError
    │   │   ├── ReadingCsvPortfolioError
    │   │   ├── ReadingExcelPortfolioError
    │   │   ├── MissingPortfolioError
    │   │   ├── MissingBenchmarkError
    │   │   └── MissingXLSXReadError
    │   ├── DataValidationError
    │   │   ├── MissingColumnError
    │   │   ├── MissingDataError
    │   │   ├── DataIntegrityError
    │   │   ├── DataAlignmentError
    │   │   │   └── SeriesAlignmentError (also ValueError)
    │   │   ├── DateRangeError
    │   │   └── NullError
    │   └── DataTransformationError
    │       ├── EntityFieldTypeError
    │       ├── TypePreservationError
    │       ├── DateParsingError
    │       │   └── DateConversionError (also ValueError)
    │       ├── DateObtentionError
    │       └── DataPipelineError
    ├── PortfolioError
    │   ├── PortfolioEntityError
    │   └── PortfolioValidationError
    ├── PerformanceAttributionError
    ├── EntityValueError
    ├── EntityTypeError
    ├── ReturnsTimeSeriesError
    │   └── ReturnsTypeError (also TypeError)
    ├── TemplateDirectoryError
    └── LicenseError (also kaxanuk.license_client.LicenseError)
        ├── LicenseConfigurationError
        ├── LicenseNotFoundError
        ├── LicenseValidationError
        └── LicenseServerError
"""

from kaxanuk import license_client


# =============================================================================
# BASE EXCEPTIONS
# =============================================================================

[docs] class AttributionAnalysisError(Exception): """ Base class for all attribution analysis exceptions. This is the root of the exception hierarchy for errors that can be caught and handled during normal operation. """
# ============================================================================= # CONFIGURATION ERRORS # =============================================================================
[docs] class ConfigurationError(AttributionAnalysisError): """ Configuration validation or parsing errors. Raised when configuration parameters are invalid, missing, or incompatible. """
[docs] class ConfigurationHandlerError(ConfigurationError): """ Error in configuration handler processing. Raised when a configuration handler (e.g., ExcelConfigurator) fails to read or parse the configuration source. """
[docs] class InjectedDependencyError(ConfigurationError): """ Error with injected dependencies. Raised when dependencies passed to the main function or factory methods do not satisfy the required interfaces or contracts. """
[docs] class AttributionArgumentError(ConfigurationError, ValueError): """ An argument of an attribution class or function is invalid or inconsistent. For example an unknown formula or linking method, missing weights, or return tables passed in a combination the class does not accept. Also a ``ValueError``, which these arguments raised before 0.4.0. """
# ============================================================================= # DATA ERRORS - Base # =============================================================================
[docs] class DataError(AttributionAnalysisError): """ Base class for all data-related errors. Covers errors during data loading, validation, and transformation. """
# ============================================================================= # DATA ERRORS - Loading # =============================================================================
[docs] class DataLoadingError(DataError): """ Errors during data loading phase. Raised when attempting to read data from files or external sources fails. """
[docs] class MissingCSVReadError(DataLoadingError): """CSV file could not be read or is missing."""
[docs] class ReadingCSVError(DataLoadingError): """Error while parsing CSV file content."""
[docs] class ReadingCsvPortfolioError(DataLoadingError): """Error reading portfolio from CSV file."""
[docs] class ReadingExcelPortfolioError(DataLoadingError): """Error reading portfolio from Excel file."""
[docs] class MissingPortfolioError(DataLoadingError): """Portfolio file not found or cannot be loaded."""
[docs] class MissingBenchmarkError(DataLoadingError): """Benchmark data file not found."""
[docs] class MissingXLSXReadError(DataLoadingError): """XLSX file could not be read or is missing."""
# ============================================================================= # DATA ERRORS - Validation # =============================================================================
[docs] class DataValidationError(DataError): """ Errors during data validation phase. Raised when loaded data fails validation checks. """
[docs] class MissingColumnError(DataValidationError): """Required column is missing from data."""
[docs] class MissingDataError(DataValidationError): """Required data is missing."""
[docs] class DataIntegrityError(DataValidationError): """Data integrity check failed."""
[docs] class DataAlignmentError(DataValidationError): """Data alignment between sources failed."""
[docs] class SeriesAlignmentError(DataAlignmentError, ValueError): """ Series that must line up have different shapes. For example portfolio, benchmark and effect series of different lengths passed to multi-period linking. Also a ``ValueError``, as before 0.4.0. """
[docs] class DateRangeError(DataValidationError): """Requested date range is not covered by input data."""
[docs] class NullError(DataValidationError): """Unexpected null/None values in data."""
# ============================================================================= # DATA ERRORS - Transformation # =============================================================================
[docs] class DataTransformationError(DataError): """ Errors during data transformation phase. Raised when data cannot be converted, parsed, or transformed to the required format or type. """
[docs] class EntityFieldTypeError(DataTransformationError): """Entity field has incorrect type."""
[docs] class TypePreservationError(DataTransformationError): """Type preservation failed during transformation."""
[docs] class DateParsingError(DataTransformationError): """Date string could not be parsed."""
[docs] class DateConversionError(DateParsingError, ValueError): """ A requested date cannot be converted to the date type of the data. Also a ``ValueError``, as before 0.4.0. """
[docs] class DateObtentionError(DataTransformationError): """Error obtaining date values from data."""
[docs] class DataPipelineError(DataTransformationError): """Error in data pipeline execution."""
# ============================================================================= # PORTFOLIO ERRORS # =============================================================================
[docs] class PortfolioError(AttributionAnalysisError): """Base class for portfolio-related errors."""
[docs] class PortfolioEntityError(PortfolioError): """Error in portfolio entity construction or access."""
[docs] class PortfolioValidationError(PortfolioError): """Portfolio validation failed."""
# ============================================================================= # ATTRIBUTION-SPECIFIC ERRORS # =============================================================================
[docs] class PerformanceAttributionError(AttributionAnalysisError): """Error in performance attribution calculations."""
[docs] class EntityValueError(AttributionAnalysisError): """Entity value is invalid."""
[docs] class EntityTypeError(AttributionAnalysisError): """Entity type is invalid."""
[docs] class ReturnsTimeSeriesError(AttributionAnalysisError): """Error in returns time series processing."""
[docs] class ReturnsTypeError(ReturnsTimeSeriesError, TypeError): """ A returns argument has an unsupported type (a pandas Series or DataFrame is expected). Also a ``TypeError``, as before 0.4.0. """
# ============================================================================= # CLI / TEMPLATE ERRORS # =============================================================================
[docs] class TemplateDirectoryError(AttributionAnalysisError): """The templates directory required by the CLI could not be located."""
# ============================================================================= # LICENSE ERRORS # =============================================================================
[docs] class LicenseError(AttributionAnalysisError, license_client.LicenseError): """ Base class for license-related errors. The license check is kaxanuk-license-client's, which raises the subclasses below: each one is also the client's matching error, so both ``except AttributionAnalysisError`` and ``except kaxanuk.license_client.LicenseError`` catch it. """
[docs] class LicenseConfigurationError(LicenseError, license_client.LicenseConfigurationError): """ The license check is misconfigured: a malformed license server URL. Raised when ``KNAA_LICENSE_SERVER_URL`` or ``KAXANUK_LICENSE_SERVER_URL`` is not an http or https URL a request can be sent to. Nothing was sent to any server. """
[docs] class LicenseNotFoundError(LicenseError, license_client.LicenseNotFoundError): """No license key was found in the environment, home, or working directory."""
[docs] class LicenseValidationError(LicenseError, license_client.LicenseValidationError): """ The license server rejected the provided license key. An unknown key, an expired or revoked license, a license that does not include Attribution Analysis, or no device seat left. """
[docs] class LicenseServerError(LicenseError, license_client.LicenseServerError): """The license server is unreachable and no saved validation can stand in for it."""
# ============================================================================= # BACKWARD COMPATIBILITY ALIASES # ============================================================================= # Keep old names that may be used elsewhere in the codebase MissingPortfolio = MissingPortfolioError MissingBenchmark = MissingBenchmarkError