Exceptions

All exceptions inherit from XLEAError, making it easy to catch any xlea error with a single except clause.

Hierarchy

XLEAError
├── ProviderError
├── HeaderNotFound
│   └── MissingRequiredColumns
├── InvalidRowError
├── UnknownFileExtensionError
└── IncompatibleReturnValueTypeError

Reference

exception xlea.exc.XLEAError[source]

Bases: Exception

exception xlea.exc.ProviderError[source]

Bases: XLEAError

exception xlea.exc.HeaderNotFound[source]

Bases: XLEAError

exception xlea.exc.InvalidRowError[source]

Bases: XLEAError

exception xlea.exc.UnknownFileExtensionError[source]

Bases: XLEAError


Error handling example

import xlea
from xlea.exc import (
    HeaderNotFound,
    MissingRequiredColumns,
    InvalidRowError,
    UnknownFileExtensionError,
    XLEAError,
)

try:
    for row in xlea.autoread("report.xlsx", schema=MySchema):
        process(row)

except MissingRequiredColumns as e:
    # More specific: tells you exactly which columns are missing
    print(f"File is missing columns: {e}")

except HeaderNotFound:
    print("Could not locate the header row in this file.")

except InvalidRowError as e:
    print(f"A data row failed validation: {e}")

except UnknownFileExtensionError:
    print("File format not supported. Install the right extra.")

except XLEAError as e:
    # Catch-all for any xlea error
    print(f"xlea error: {e}")