Skip to main content
Version: 0.3.0
Last Verified: 2025-01-27
Package: hopx-ai on PyPI

Overview

The Python SDK provides a comprehensive error hierarchy for handling different types of errors. All errors inherit from HopxError and provide detailed error information.

Import

Base Error

HopxError

Base exception for all HopX SDK errors. Fields:
  • message (str): Error message
  • code (str, optional): Error code
  • request_id (str, optional): Request ID for debugging
  • status_code (int, optional): HTTP status code
  • details (Dict[str, Any], optional): Additional error details
Example:
Expected Output:

API Errors

APIError

Base class for API request failures. Inherits from: HopxError Fields:
  • status_code (int): HTTP status code

AuthenticationError

Authentication failed (401). Inherits from: APIError When raised:
  • Invalid or missing API key
  • Expired authentication token
Example:
Expected Output:

NotFoundError

Resource not found (404). Inherits from: APIError When raised:
  • Sandbox not found
  • Template not found
  • File not found
Example:
Expected Output:

ValidationError

Request validation failed (400). Inherits from: APIError Fields:
  • field (str, optional): Field that failed validation
When raised:
  • Invalid parameters
  • Missing required fields
  • Invalid data format
Example:
Expected Output:

RateLimitError

Rate limit exceeded (429). Inherits from: APIError Fields:
  • retry_after (int, optional): Seconds to wait before retrying
When raised:
  • Too many requests in a time period
Example:
Expected Output:

ResourceLimitError

Resource limit exceeded. Inherits from: APIError Fields:
  • limit (int): Resource limit
  • current (int): Current usage
  • available (int): Available resources
  • upgrade_url (str, optional): URL to upgrade plan
When raised:
  • Exceeded sandbox quota
  • Insufficient resources
Example:
Expected Output:

ServerError

Server error (5xx). Inherits from: APIError When raised:
  • Internal server error
  • Service unavailable

Network Errors

NetworkError

Network communication failed. Inherits from: HopxError When raised:
  • Connection errors
  • DNS resolution failures

TimeoutError

Request timed out. Inherits from: NetworkError When raised:
  • Request exceeded timeout
  • Operation took too long
Example:
Expected Output:

Agent Errors

AgentError

Base error for agent operations. Inherits from: HopxError

FileNotFoundError

File or directory not found in sandbox. Inherits from: AgentError Fields:
  • path (str): Path that was not found
Example:
Expected Output:

FileOperationError

File operation failed. Inherits from: AgentError Fields:
  • operation (str): Operation that failed
Example:
Expected Output:

CodeExecutionError

Code execution failed. Inherits from: AgentError Fields:
  • language (str): Language that failed
Example:
Expected Output:

CommandExecutionError

Command execution failed. Inherits from: AgentError Fields:
  • command (str): Command that failed
Example:
Expected Output:

DesktopNotAvailableError

Desktop automation not available in this sandbox. Inherits from: AgentError Fields:
  • missing_dependencies (List[str]): Missing dependencies
  • docs_url (str, optional): Documentation URL
  • install_command (str, optional): Installation command
Example:
Expected Output:

Error Handling Examples

Example 1: Basic Error Handling

Expected Output:

Example 2: Specific Error Handling

Expected Output:

Example 3: Retry on Rate Limit

Expected Output:

  • Models - Data models
  • Sandbox - Sandbox operations that may raise errors

See Also

Next Steps

Now that you understand error handling, explore: