Skip to content

Exceptions API

The Manticore CockroachDB client defines custom exceptions to handle specific error cases.

Class Documentation

TableNotInitializedError

Bases: DatabaseError

Raised when trying to use a table that has not been initialized.

Source code in manticore_cockroachdb/crud/exceptions.py
class TableNotInitializedError(DatabaseError):
    """Raised when trying to use a table that has not been initialized."""

    def __init__(self, table_name: str):
        """Initialize table not initialized error.

        Args:
            table_name: Name of the table that is not initialized
        """
        super().__init__(f"Table '{table_name}' is not initialized")
        self.table_name = table_name

Functions

__init__(table_name)

Initialize table not initialized error.

Parameters:

Name Type Description Default
table_name str

Name of the table that is not initialized

required
Source code in manticore_cockroachdb/crud/exceptions.py
def __init__(self, table_name: str):
    """Initialize table not initialized error.

    Args:
        table_name: Name of the table that is not initialized
    """
    super().__init__(f"Table '{table_name}' is not initialized")
    self.table_name = table_name

Usage Examples

from manticore_cockroachdb import Database, Table
from manticore_cockroachdb.crud.exceptions import TableNotInitializedError

# Connect to database
db = Database(database="example_db")

# Create a Table instance without initializing
users = Table("users")

try:
    # Attempt to use the table before initializing
    user = users.create({"name": "John Doe", "email": "john@example.com"})
except TableNotInitializedError as e:
    print(f"Error: {e}")
    # Initialize the table
    users.db = db

# Now the table can be used
user = users.create({"name": "John Doe", "email": "john@example.com"})
print(f"Created user with ID: {user['id']}")