Skip to main content

loom_rs/
error.rs

1//! Error types for loom-rs.
2
3use thiserror::Error;
4
5/// Errors that can occur when building or using a Loom runtime.
6#[derive(Debug, Error)]
7pub enum LoomError {
8    /// Error parsing CPU set string.
9    #[error("invalid cpuset format: {0}")]
10    InvalidCpuSet(String),
11
12    /// CPU ID is not available on this system.
13    #[error("CPU {0} is not available on this system")]
14    CpuNotAvailable(usize),
15
16    /// No CPUs available after applying constraints.
17    #[error("no CPUs available after applying constraints")]
18    NoCpusAvailable,
19
20    /// Error extracting configuration from figment.
21    #[error("configuration error: {0}")]
22    Config(#[from] Box<figment::Error>),
23
24    /// Error building tokio runtime.
25    #[error("failed to build tokio runtime: {0}")]
26    TokioRuntime(#[from] std::io::Error),
27
28    /// Error building rayon thread pool.
29    #[error("failed to build rayon thread pool: {0}")]
30    RayonThreadPool(#[from] rayon::ThreadPoolBuildError),
31
32    /// Error setting thread affinity.
33    #[error("failed to set thread affinity for CPU {0}")]
34    AffinityFailed(usize),
35
36    /// CUDA-related errors (feature-gated).
37    #[cfg(feature = "cuda")]
38    #[error("CUDA error: {0}")]
39    Cuda(String),
40
41    /// NVML initialization or query error (feature-gated).
42    #[cfg(feature = "cuda")]
43    #[error("NVML error: {0}")]
44    Nvml(#[from] nvml_wrapper::error::NvmlError),
45
46    /// Thread count mismatch - not enough CPUs for requested threads.
47    #[error("requested {requested} threads but only {available} CPUs available")]
48    InsufficientCpus { requested: usize, available: usize },
49
50    /// Cannot specify both cuda_device and cpuset.
51    #[cfg(feature = "cuda")]
52    #[error("cannot specify both cuda_device and cpuset; cuda_device implies its local cpuset")]
53    CudaCpusetConflict,
54}
55
56/// Result type alias for Loom operations.
57pub type Result<T> = std::result::Result<T, LoomError>;