kronos_compute/implementation/
error.rs

1//! Error types for Kronos implementation
2
3use std::fmt;
4use crate::VkResult;
5
6/// Errors that can occur in the ICD loader
7#[derive(Debug)]
8pub enum IcdError {
9    /// Failed to create CString (contains null byte)
10    InvalidString(std::ffi::NulError),
11    /// Failed to load dynamic library
12    LibraryLoadFailed(String),
13    /// Required function not found in library
14    MissingFunction(&'static str),
15    /// Failed to parse ICD manifest
16    InvalidManifest(String),
17    /// No ICD manifest files found
18    NoManifestsFound,
19    /// Mutex was poisoned
20    MutexPoisoned,
21    /// Path has no parent directory
22    InvalidPath(String),
23    /// Vulkan API error
24    VulkanError(VkResult),
25    /// Invalid operation
26    InvalidOperation(&'static str),
27    /// No ICD loaded
28    NoIcdLoaded,
29}
30
31impl fmt::Display for IcdError {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        match self {
34            IcdError::InvalidString(e) => write!(f, "Invalid string: {}", e),
35            IcdError::LibraryLoadFailed(path) => write!(f, "Failed to load library: {}", path),
36            IcdError::MissingFunction(name) => write!(f, "Missing function: {}", name),
37            IcdError::InvalidManifest(msg) => write!(f, "Invalid manifest: {}", msg),
38            IcdError::NoManifestsFound => write!(f, "No ICD manifest files found"),
39            IcdError::MutexPoisoned => write!(f, "Mutex was poisoned"),
40            IcdError::InvalidPath(path) => write!(f, "Invalid path: {}", path),
41            IcdError::VulkanError(result) => write!(f, "Vulkan error: {:?}", result),
42            IcdError::InvalidOperation(op) => write!(f, "Invalid operation: {}", op),
43            IcdError::NoIcdLoaded => write!(f, "No ICD loaded"),
44        }
45    }
46}
47
48impl std::error::Error for IcdError {}
49
50impl From<std::ffi::NulError> for IcdError {
51    fn from(e: std::ffi::NulError) -> Self {
52        IcdError::InvalidString(e)
53    }
54}
55
56/// General Kronos errors
57#[derive(Debug)]
58pub enum KronosError {
59    /// ICD loader error
60    IcdError(IcdError),
61    /// Mutex was poisoned
62    MutexPoisoned,
63}
64
65impl fmt::Display for KronosError {
66    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67        match self {
68            KronosError::IcdError(e) => write!(f, "ICD error: {}", e),
69            KronosError::MutexPoisoned => write!(f, "Mutex was poisoned"),
70        }
71    }
72}
73
74impl std::error::Error for KronosError {}
75
76impl From<IcdError> for KronosError {
77    fn from(e: IcdError) -> Self {
78        KronosError::IcdError(e)
79    }
80}
81
82// Helper for mutex lock errors
83impl<T> From<std::sync::PoisonError<T>> for IcdError {
84    fn from(_: std::sync::PoisonError<T>) -> Self {
85        IcdError::MutexPoisoned
86    }
87}
88
89impl<T> From<std::sync::PoisonError<T>> for KronosError {
90    fn from(_: std::sync::PoisonError<T>) -> Self {
91        KronosError::MutexPoisoned
92    }
93}