SmolVMError class, making it easy to catch all SmolVM-related errors or handle specific error types.
Exception Hierarchy
Base Exception
SmolVMError
Base exception for all SmolVM errors. All other exceptions inherit from this class. Attributes:message(str): Human-readable error messagedetails(dict): Additional error context and metadata
VM Lifecycle Exceptions
VMAlreadyExistsError
Raised when attempting to create a VM with an ID that already exists. Attributes:vm_id(str): The conflicting VM IDmessage(str): Error messagedetails(dict): Containsvm_id
- Creating a new VM when a VM with the same ID already exists
VMNotFoundError
Raised when attempting to access a VM that doesn’t exist. Attributes:vm_id(str): The VM ID that was not foundmessage(str): Error messagedetails(dict): Containsvm_id
- Calling
SmolVM.from_id()with a non-existent VM ID - Attempting operations on a deleted VM
Validation Exceptions
ValidationError
Raised when input validation fails, such as invalid configuration parameters. When raised:- Invalid VM configuration (e.g., invalid CPU count, memory size)
- Invalid network configuration
- Invalid image paths or URLs
- Malformed parameters
Network Exceptions
NetworkError
Raised when network operations fail, including TAP device creation, NAT configuration, or IP allocation. When raised:- Failed to create TAP device
- Failed to configure NAT rules
- IP address allocation errors
- Network interface configuration failures
Host Environment Exceptions
HostError
Raised when host environment checks fail, such as missing KVM support, dependencies, or Firecracker binary. When raised:- KVM is not available or accessible
- Firecracker binary not found
- Missing system dependencies
- Insufficient permissions for virtualization
Image Exceptions
ImageError
Raised when image operations fail, including download errors, checksum validation, or cache issues. When raised:- Failed to download kernel or rootfs image
- Checksum verification failed
- Cache directory access errors
- Image file corruption
Firecracker API Exceptions
FirecrackerAPIError
Raised when Firecracker API calls fail. Attributes:status_code(int | None): HTTP status code from Firecracker APImessage(str): Error messagedetails(dict): Containsstatus_code
- Firecracker API returns an error response
- Failed to communicate with Firecracker socket
- Invalid API requests
Timeout Exceptions
OperationTimeoutError
Raised when an operation exceeds its timeout duration. Attributes:operation(str): Name of the operation that timed outtimeout_seconds(float): Timeout duration in secondsmessage(str): Error messagedetails(dict): Containsoperationandtimeout_seconds
- VM boot timeout
- Command execution timeout
- API call timeout
TimeoutError
Backward-compatible alias forOperationTimeoutError. Use OperationTimeoutError in new code.
Command Execution Exceptions
CommandExecutionUnavailableError
Raised when command execution is not available for a VM, typically because the VM profile doesn’t support SSH. Attributes:vm_id(str): The VM IDreason(str): Why command execution is unavailableremediation(str | None): Suggested fix if availablemessage(str): Error message with reason and remediationdetails(dict): Containsvm_idandreason
- Attempting to run commands on a VM without SSH support
- SSH is not configured in the kernel boot arguments
- VM is not running or not accessible
Error Handling Best Practices
Catch Specific Exceptions
Catch specific exceptions when you can handle them appropriately:Catch All SmolVM Errors
Use the baseSmolVMError to catch all SmolVM-related errors:
Access Error Details
All exceptions provide adetails dictionary with additional context: