Exceptions¶
All library exceptions inherit from MixpanelDataError, enabling callers to catch all library errors with a single except clause.
Explore on DeepWiki
Ask questions about specific exceptions, error recovery patterns, or debugging strategies.
Exception Hierarchy¶
MixpanelDataError
├── ConfigError
│ ├── AccountNotFoundError
│ └── AccountExistsError
├── APIError
│ ├── AuthenticationError
│ ├── RateLimitError
│ ├── QueryError
│ ├── ServerError
│ └── JQLSyntaxError
├── TableExistsError
├── TableNotFoundError
├── DatabaseLockedError
└── DatabaseNotFoundError
Catching Errors¶
import mixpanel_data as mp
try:
ws = mp.Workspace()
result = ws.segmentation(event="Purchase", from_date="2025-01-01", to_date="2025-01-31")
except mp.AuthenticationError as e:
print(f"Auth failed: {e.message}")
except mp.RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except mp.MixpanelDataError as e:
print(f"Error [{e.code}]: {e.message}")
Base Exception¶
mixpanel_data.MixpanelDataError
¶
MixpanelDataError(
message: str,
code: str = "UNKNOWN_ERROR",
details: dict[str, Any] | None = None,
)
Bases: Exception
Base exception for all mixpanel_data errors.
All library exceptions inherit from this class, allowing callers to: - Catch all library errors: except MixpanelDataError - Handle specific errors: except AccountNotFoundError - Serialize errors: error.to_dict()
Initialize exception.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
code
|
Machine-readable error code for programmatic handling.
TYPE:
|
details
|
Additional structured data about the error.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
API Exceptions¶
mixpanel_data.APIError
¶
APIError(
message: str,
*,
status_code: int,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
request_body: dict[str, Any] | None = None,
code: str = "API_ERROR",
)
Bases: MixpanelDataError
Base class for Mixpanel API HTTP errors.
Provides structured access to HTTP request/response context for debugging and automated recovery by AI agents. All API-related exceptions inherit from this class, enabling agents to:
- Understand what went wrong (status code, error message)
- See exactly what was sent (request method, URL, params, body)
- See exactly what came back (response body, headers)
- Modify their approach and retry autonomously
Example
Initialize APIError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code from response.
TYPE:
|
response_body
|
Raw response body (string or parsed dict).
TYPE:
|
request_method
|
HTTP method used (GET, POST).
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
request_body
|
Request body sent (for POST requests).
TYPE:
|
code
|
Machine-readable error code.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
response_body
property
¶
Raw response body (string or parsed dict).
mixpanel_data.AuthenticationError
¶
AuthenticationError(
message: str = "Authentication failed",
*,
status_code: int = 401,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
)
Bases: APIError
Authentication with Mixpanel API failed (HTTP 401).
Raised when credentials are invalid, expired, or lack required permissions. Inherits from APIError to provide full request/response context.
Example
Initialize AuthenticationError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code (default 401).
TYPE:
|
response_body
|
Raw response body.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.RateLimitError
¶
RateLimitError(
message: str = "Rate limit exceeded",
*,
retry_after: int | None = None,
status_code: int = 429,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
)
Bases: APIError
Mixpanel API rate limit exceeded (HTTP 429).
Raised when the API returns a 429 status. The retry_after property indicates when the request can be retried. Inherits from APIError to provide full request context for debugging.
Example
Initialize RateLimitError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
retry_after
|
Seconds until retry is allowed (from Retry-After header).
TYPE:
|
status_code
|
HTTP status code (default 429).
TYPE:
|
response_body
|
Raw response body.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.QueryError
¶
QueryError(
message: str = "Query execution failed",
*,
status_code: int = 400,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
request_body: dict[str, Any] | None = None,
)
Bases: APIError
Query execution failed (HTTP 400 or query-specific error).
Raised when an API query fails due to invalid parameters, syntax errors, or other query-specific issues. Inherits from APIError to provide full request/response context for debugging.
Example
Initialize QueryError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code (default 400).
TYPE:
|
response_body
|
Raw response body with error details.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
request_body
|
Request body sent (for POST).
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.ServerError
¶
ServerError(
message: str = "Server error",
*,
status_code: int = 500,
response_body: str | dict[str, Any] | None = None,
request_method: str | None = None,
request_url: str | None = None,
request_params: dict[str, Any] | None = None,
request_body: dict[str, Any] | None = None,
)
Bases: APIError
Mixpanel server error (HTTP 5xx).
Raised when the Mixpanel API returns a server error. These are typically transient issues that may succeed on retry. The response_body property contains the full error details from Mixpanel, which often include actionable information (e.g., "unit and interval both specified").
Example
Initialize ServerError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
status_code
|
HTTP status code (5xx).
TYPE:
|
response_body
|
Raw response body with error details.
TYPE:
|
request_method
|
HTTP method used.
TYPE:
|
request_url
|
Full request URL.
TYPE:
|
request_params
|
Query parameters sent.
TYPE:
|
request_body
|
Request body sent (for POST).
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.JQLSyntaxError
¶
Bases: QueryError
JQL script execution failed with syntax or runtime error (HTTP 412).
Raised when a JQL script fails to execute due to syntax errors, type errors, or other JavaScript runtime issues. Provides structured access to error details from Mixpanel's response.
Inherits from QueryError (and thus APIError) to provide full HTTP context.
Example
Initialize JQLSyntaxError.
| PARAMETER | DESCRIPTION |
|---|---|
raw_error
|
Raw error string from Mixpanel API response.
TYPE:
|
script
|
The JQL script that caused the error.
TYPE:
|
request_path
|
API request path from error response.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
Configuration Exceptions¶
mixpanel_data.ConfigError
¶
Bases: MixpanelDataError
Base for configuration-related errors.
Raised when there's a problem with configuration files, environment variables, or credential resolution.
Initialize ConfigError.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
Human-readable error message.
TYPE:
|
details
|
Additional structured data.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.AccountNotFoundError
¶
Bases: ConfigError
Named account does not exist in configuration.
Raised when attempting to access an account that hasn't been configured. The available_accounts property lists valid account names to help users.
Initialize AccountNotFoundError.
| PARAMETER | DESCRIPTION |
|---|---|
account_name
|
The requested account name that wasn't found.
TYPE:
|
available_accounts
|
List of valid account names for suggestions.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.AccountExistsError
¶
Bases: ConfigError
Account name already exists in configuration.
Raised when attempting to add an account with a name that's already in use.
Initialize AccountExistsError.
| PARAMETER | DESCRIPTION |
|---|---|
account_name
|
The conflicting account name.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
Storage Exceptions¶
Storage exceptions are raised during fetch and table operations:
| Exception | Raised When |
|---|---|
TableExistsError |
Fetching to an existing table without append=True or --replace |
TableNotFoundError |
Using append=True on a non-existent table |
DatabaseLockedError |
Another process has the database locked |
DatabaseNotFoundError |
Database file not found in read-only mode |
mixpanel_data.TableExistsError
¶
Bases: MixpanelDataError
Table already exists in local database.
Raised when attempting to create a table that already exists. Use drop() first to remove the existing table.
Initialize TableExistsError.
| PARAMETER | DESCRIPTION |
|---|---|
table_name
|
Name of the existing table.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.TableNotFoundError
¶
Bases: MixpanelDataError
Table does not exist in local database.
Raised when attempting to access a table that hasn't been created.
Initialize TableNotFoundError.
| PARAMETER | DESCRIPTION |
|---|---|
table_name
|
Name of the missing table.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.DatabaseLockedError
¶
Bases: MixpanelDataError
Database is locked by another process.
Raised when attempting to access a DuckDB database that is locked by another process. DuckDB uses single-writer, multiple-reader concurrency - only one process can have write access at a time.
Example
Initialize DatabaseLockedError.
| PARAMETER | DESCRIPTION |
|---|---|
db_path
|
Path to the locked database file.
TYPE:
|
holding_pid
|
Process ID holding the lock, if available.
TYPE:
|
Source code in src/mixpanel_data/exceptions.py
mixpanel_data.DatabaseNotFoundError
¶
Bases: MixpanelDataError
Database file does not exist.
Raised when attempting to open a non-existent database file in read-only mode. DuckDB cannot create a new database file when opened read-only.
This typically happens when running read-only commands (like mp query
or mp inspect tables) before any data has been fetched.
Example
Initialize DatabaseNotFoundError.
| PARAMETER | DESCRIPTION |
|---|---|
db_path
|
Path to the database file that doesn't exist.
TYPE:
|