Skip to main content
tif1 uses a structured exception hierarchy to help you handle errors gracefully. All exceptions inherit from TIF1Error and include contextual information.

Exception Hierarchy


Base Exception

TIF1Error

Base exception for all tif1 errors. All exceptions accept **context kwargs for structured error information.
Attributes:
  • message: Error message string
  • context: Dictionary of contextual information
Example:

Data Errors

DataNotFoundError

Raised when requested data is not available in the CDN.
Context:
  • year: The requested year
  • event: The requested event name
  • session: The requested session name
Example:

DriverNotFoundError

Raised when a driver code is not found in the session.
Context:
  • driver: The requested driver code
Example:
Context:
  • lap_number: The requested lap number
  • driver: The driver code
Example:

Network Errors

NetworkError

Raised when network requests fail after all retries and CDN fallbacks are exhausted.
Context:
  • url: The URL that failed
  • status_code: HTTP status code (if available)
Example:

Data validation errors

InvalidDataError

Raised when fetched data is invalid, corrupted, or fails validation.
Context:
  • reason: Description of why the data is invalid
Example:

Cache Errors

CacheError

Raised when cache operations fail (e.g., SQLite errors, disk full).
Example:
Context:
  • attribute: The attribute that was accessed
Example:

Error handling patterns

Basic Try-Catch

Specific error handling

Retry with Fallback

Context-aware error handling

Graceful Degradation


Best Practices

  1. Catch specific exceptions first: Handle DriverNotFoundError before DataNotFoundError, and DataNotFoundError before TIF1Error.
  2. Use context information: All exceptions include structured context via the context attribute.
  3. Don’t swallow errors silently: Always log or handle errors appropriately.
  4. Implement retries for network errors: Network errors are often transient.
  5. Validate user input early: Check driver codes and lap numbers before making expensive API calls.
  6. Use try-finally for cleanup: Ensure resources are cleaned up even if errors occur.
Last modified on March 5, 2026