Skip to main content
BoxLite provides a structured exception hierarchy for error handling and metrics classes for monitoring resource usage across boxes.

Error Types

Exception Hierarchy

BoxliteError

Base exception for all BoxLite errors. Catch this to handle any BoxLite-specific error.

ExecError

Raised when a command execution fails (non-zero exit code).

TimeoutError

Raised when an operation times out.

ParseError

Raised when output parsing fails.

Core Error Variants

BoxLite uses a centralized error enum internally. These are surfaced as BoxliteError exceptions in Python with descriptive messages.

UnsupportedEngine

Platform or hypervisor not supported. Cause:
  • Running on Windows
  • Running on Intel Mac
  • KVM not available on Linux
  • Hypervisor.framework not available on macOS
Example:
Solution:
  • Use supported platform (macOS ARM64, Linux x86_64/ARM64)
  • Verify hypervisor availability:
    • Linux: grep -E 'vmx|svm' /proc/cpuinfo
    • macOS: Ensure macOS 12+ on Apple Silicon

Engine(String)

Hypervisor or VM engine error. Cause:
  • KVM module not loaded
  • Insufficient permissions for /dev/kvm
  • Hypervisor.framework error
  • VM creation failed
Example:
Solution:

Config(String)

Invalid box configuration. Cause:
  • Invalid CPU count (< 1 or > host CPUs)
  • Invalid memory size (< 128 or > 65536)
  • Invalid paths in volumes
  • Invalid port numbers
Example:
Solution:
  • Verify configuration parameters are within valid ranges
  • Check file paths exist for volume mounts
  • Ensure port numbers are valid (1-65535)

Storage(String)

Filesystem or disk operation error. Cause:
  • Disk full (~/.boxlite partition)
  • Permission denied writing to ~/.boxlite
  • Disk image creation failed
  • QCOW2 operation failed
Example:
Solution:

Image(String)

OCI image pull or extraction error. Cause:
  • Network connectivity issues
  • Invalid image name or tag
  • Registry authentication required
  • Image not found in registry
  • Corrupted image layers
Example:
Solution:

Portal(String)

Host-guest communication error (gRPC over vsock). Cause:
  • Guest agent not responding
  • vsock connection failed
  • gRPC timeout
  • Guest initialization failed
Example:
Solution:
  • Enable debug logging: RUST_LOG=debug
  • Check if box is running: box.info().status
  • Restart box: box.stop() and recreate
  • Report issue with logs if persists

Network(String)

Network configuration or connectivity error. Cause:
  • gvproxy not running or crashed
  • Port already in use
  • Network backend initialization failed
Example:
Solution:

Execution(String)

Command execution error. Cause:
  • Command not found in image
  • Command crashed or killed
  • Execution timeout
  • Streaming I/O error
Example:
Solution:
  • Verify command exists in image:
  • Check exit code and stderr:

Internal(String)

Internal BoxLite error. Cause:
  • Unexpected internal state
  • I/O error
  • JSON parsing error
  • Unhandled edge case
Example:
Solution:
  • Enable debug logging: RUST_LOG=debug python script.py
  • Report issue with full logs to GitHub
  • Include BoxLite version, platform, and reproduction steps

NotFound(String)

Box or resource not found. Cause:
  • Box ID does not exist
  • Box was removed
  • Image not in cache
Example:
Solution:
  • List all boxes: runtime.list()
  • Verify box ID is correct
  • Create new box if needed

AlreadyExists(String)

Box or resource already exists. Cause:
  • Duplicate box creation attempt
  • Port already forwarded
Example:
Solution:
  • Use existing box: runtime.get(box_id)
  • Remove existing box: box.remove()
  • Use different configuration (e.g., different port)

InvalidState(String)

Box is in wrong state for requested operation. Cause:
  • Executing command on stopped box
  • Stopping already stopped box
  • Restarting box that never started
Example:
Solution:
  • Check box status: info = await box.info(); print(info.status)
  • Restart box if stopped: runtime.get(box_id) (may auto-restart)
  • Create new box if needed

Error Handling Patterns

Basic Error Handling

Catching Specific Errors

Retry Pattern

Metrics

boxlite.RuntimeMetrics

Aggregate metrics across all boxes managed by a runtime instance.

boxlite.BoxMetrics

Per-box resource usage metrics. Retrieved via box.metrics().
box.metrics() is available on the low-level Box object (returned by runtime.create()). SimpleBox does not expose a metrics() method.

Monitoring Example

Runtime-wide Monitoring

See Also