Skip to content
prasad-kumkar edited this page May 5, 2025 · 1 revision

Error Handling

The jam.error module provides a standardized approach to error handling throughout the Tessera implementation.

Error Types

Tessera defines a hierarchy of error types to handle different categories of errors:

  • JamError - Base exception class for all Tessera errors
    • ConfigError - Configuration-related errors
    • NetworkError - Network communication errors
    • ConsensusError - Errors in consensus mechanisms
    • ValidationError - Block or transaction validation errors
    • StateError - State management errors
    • StorageError - Database and storage errors
    • CryptoError - Cryptography-related errors

Usage

from jam.error import JamError, ValidationError

def validate_block(block):
    try:
        # Validation logic
        if not is_valid_format(block):
            raise ValidationError("Invalid block format")
        if not valid_signature(block):
            raise ValidationError("Invalid block signature")
    except ValidationError as e:
        # Handle validation errors
        logger.error(f"Block validation failed: {e}")
        return False
    except JamError as e:
        # Handle other Tessera errors
        logger.error(f"Unexpected error during validation: {e}")
        return False
    except Exception as e:
        # Handle unexpected errors
        logger.error(f"System error: {e}")
        return False
    
    return True

Best Practices

When working with errors in Tessera:

  1. Specific Exceptions: Use the most specific error type for the situation
  2. Error Context: Include relevant context in error messages
  3. Error Propagation: Handle errors at the appropriate level
  4. Error Logging: Log errors with appropriate severity
  5. Custom Errors: Extend the base classes when creating custom errors

Clone this wiki locally