Exceptions Module

wsqlite provides a comprehensive exception hierarchy for error handling.

Base Exception

exception wsqlite.exceptions.WSQLiteError(message: str, details: dict = None)[source]

Bases: Exception

Base exception for wsqlite library.

All other wsqlite exceptions inherit from this class.

__init__(message: str, details: dict = None)[source]

Connection Errors

exception wsqlite.exceptions.ConnectionError(message: str, details: dict = None)[source]

Bases: WSQLiteError

Exception raised for connection-related errors.

Examples

  • Database file not found

  • Permission denied

  • Invalid connection parameters

Sync Errors

exception wsqlite.exceptions.TableSyncError(message: str, details: dict = None)[source]

Bases: WSQLiteError

Exception raised during table synchronization operations.

Examples

  • Failed to create table

  • Column type mismatch during sync

  • Invalid index creation

Validation Errors

exception wsqlite.exceptions.ValidationError(message: str, details: dict = None)[source]

Bases: WSQLiteError

Exception raised for data validation failures.

Examples

  • Invalid field type for Pydantic model

  • Missing required field

  • Field validation rule violation

Operation Errors

exception wsqlite.exceptions.OperationError(message: str, query: str = None, params: tuple = None)[source]

Bases: WSQLiteError

Exception raised for general database operation failures.

This is a catch-all for database errors that don’t fit other categories.

Examples

  • Query syntax error

  • Constraint violation

  • Foreign key violation

  • Unique constraint violation

__init__(message: str, query: str = None, params: tuple = None)[source]

SQL Injection Error

exception wsqlite.exceptions.SQLInjectionError(identifier: str)[source]

Bases: WSQLiteError

Raised when potential SQL injection is detected.

This is a security feature. The library validates all identifiers (table names, column names) to prevent SQL injection attacks.

Only alphanumeric characters and underscores are allowed in identifiers.

__init__(identifier: str)[source]

Transaction Errors

exception wsqlite.exceptions.TransactionError(message: str, details: dict = None)[source]

Bases: WSQLiteError

Exception raised for transaction-related errors.

Examples

  • Transaction already committed

  • Transaction already rolled back

  • Nested transactions not supported

  • Savepoint errors

Exception Hierarchy

WSQLiteError (base)
├── ConnectionError
├── TableSyncError
├── ValidationError
├── OperationError
├── SQLInjectionError
└── TransactionError

Example Usage

from wsqlite import WSQLite
from wsqlite.exceptions import SQLInjectionError, TransactionError

try:
    db = WSQLite(User, "database.db")
    db.insert(user)
except TransactionError as e:
    print(f"Transaction failed: {e}")

# Catch specific exceptions
try:
    # Validate identifier
    from wsqlite.core.repository import validate_identifier
    validate_identifier("users; DROP TABLE")
except SQLInjectionError:
    print("SQL injection attempt detected!")

# Catch all wsqlite errors
except WSQLiteError as e:
    print(f"wsqlite error: {e}")