Overview
SmolVM defines a comprehensive exception hierarchy to provide granular error handling. All exceptions inherit from the baseSmolVMError class, which includes structured error details.
Exception Hierarchy
Base Exception
SmolVMError
Base exception for all SmolVM errors. Provides structured error information. Attributes:message(str): Human-readable error messagedetails(dict): Additional structured error context
VM Lifecycle Exceptions
VMAlreadyExistsError
Raised when attempting to create a VM with an ID that already exists in the database. Attributes:vm_id(str): The conflicting VM identifier
- Calling
vm.create()with a VM ID that’s already registered - Using
SmolVMManager.create_vm()with a duplicate ID
VMNotFoundError
Raised when attempting to access a VM that doesn’t exist in the database. Attributes:vm_id(str): The VM identifier that was not found
- Calling
VM.from_id()with a non-existent VM ID - Using
SmolVMManager.get_vm()for an unknown VM - Operating on a deleted VM
Configuration Exceptions
ValidationError
Raised when input validation fails. This includes Pydantic validation errors fromVMConfig, invalid paths, or malformed parameters.
When raised:
- Invalid
VMConfigparameters (e.g.,vcpu_countout of range) - Non-existent kernel or rootfs paths
- Invalid environment variable names
- Malformed VM IDs
Infrastructure Exceptions
NetworkError
Raised when network operations fail, including TAP device creation, NAT rule setup, or IP allocation. When raised:- TAP device creation fails (permissions, name conflicts)
- IP address allocation exhaustion
- NAT/port forwarding setup failures
- Network cleanup issues
HostError
Raised when host environment validation fails. This includes missing KVM support, Firecracker binary issues, or insufficient permissions. When raised:- KVM device
/dev/kvmis not accessible - Firecracker binary not found or not executable
- Missing required system dependencies
- Insufficient host resources
ImageError
Raised when image operations fail, including downloads, checksum verification, or cache management. When raised:- Image download failures
- Checksum mismatches
- Cache directory access issues
- Corrupt image files
Runtime Exceptions
FirecrackerAPIError
Raised when Firecracker API calls fail. This includes configuration errors, state transition failures, or communication issues with the Firecracker process. Attributes:status_code(int | None): HTTP status code from Firecracker API (if applicable)
- Firecracker API rejects a configuration
- State transitions fail (e.g., starting an already-running VM)
- Communication with Unix socket fails
- Invalid API requests
OperationTimeoutError
Raised when an operation exceeds its timeout limit. This includes VM boot timeouts, SSH connection timeouts, or command execution timeouts. Attributes:operation(str): Name of the operation that timed outtimeout_seconds(float): The timeout duration that was exceeded
- VM fails to boot within the timeout period
- SSH connection cannot be established
- Command execution hangs
TimeoutError is available as a backward-compatible alias for OperationTimeoutError.
CommandExecutionUnavailableError
Raised when attempting to execute commands on a VM that doesn’t support command execution, typically because SSH is not configured or available. Attributes:vm_id(str): The VM identifierreason(str): Why command execution is unavailableremediation(str | None): Suggested fix
- VM was created without SSH-enabled boot args
- SSH server is not running in the guest
- Network is not configured
Exception Handling Best Practices
Catch Specific Exceptions
Use Error Details
Graceful Degradation
Context Managers for Cleanup
Related
- SmolVM API - Methods that may raise these exceptions
- VMConfig - Configuration validation
- Troubleshooting - Common issues and solutions