1use thiserror::Error;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
5pub enum ValidationReason {
6 #[error("must not be empty")]
8 Empty,
9
10 #[error("must be at most 64 characters")]
12 IdentifierTooLong,
13
14 #[error("must be at most 253 characters")]
16 HostnameTooLong,
17
18 #[error("must start with an ASCII letter or digit")]
20 InvalidStartCharacter,
21
22 #[error("must contain only lowercase ASCII letters, digits, '-' or '_'")]
24 InvalidCharacters,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
29pub enum AllocationReason {
30 #[error("allocation size must be greater than zero")]
32 ZeroSize,
33 #[error("allocation size exceeds maximum supported size")]
35 ExceedsMaxSize,
36}
37
38#[derive(Debug, Error)]
40pub enum LavaFlowError {
41 #[error("invalid process name `{value}`: {reason}")]
43 InvalidProcessName {
44 value: String,
46 reason: ValidationReason,
48 },
49
50 #[error("invalid channel id `{value}`: {reason}")]
52 InvalidChannelId {
53 value: String,
55 reason: ValidationReason,
57 },
58
59 #[error("invalid hostname `{value}`: {reason}")]
61 InvalidHostname {
62 value: String,
64 reason: ValidationReason,
66 },
67
68 #[error("failed to detect local hostname")]
70 HostnameDetection(#[source] std::io::Error),
71
72 #[error("invalid allocation request (size={size}): {reason}")]
74 InvalidAllocationRequest {
75 size: usize,
77 reason: AllocationReason,
79 },
80
81 #[error("GPU device `{device_id}` not found")]
83 GpuDeviceNotFound {
84 device_id: u32,
86 },
87
88 #[error("unsupported interprocess handle for operation: {kind}")]
90 UnsupportedInterprocessHandle {
91 kind: &'static str,
93 },
94
95 #[error("GPU backend is not available")]
97 GpuBackendUnavailable,
98
99 #[error("vulkan operation failed during {operation}: {details}")]
101 VulkanOperation {
102 operation: &'static str,
104 details: String,
106 },
107
108 #[error("allocator state lock poisoned: {component}")]
110 AllocatorStatePoisoned {
111 component: &'static str,
113 },
114
115 #[error("shared memory operation failed during {operation}")]
117 SharedMemoryOperation {
118 operation: &'static str,
120 #[source]
122 source: std::io::Error,
123 },
124
125 #[error("channel metadata codec failed during {operation}")]
127 ChannelMetadataCodec {
128 operation: &'static str,
130 #[source]
132 source: serde_json::Error,
133 },
134
135 #[error("unsupported metadata encoding: {encoding}")]
137 UnsupportedMetadataEncoding {
138 encoding: &'static str,
140 },
141
142 #[error("channel transport operation failed during {operation}")]
144 ChannelTransportOperation {
145 operation: &'static str,
147 #[source]
149 source: std::io::Error,
150 },
151
152 #[error("channel transport disconnected")]
154 ChannelDisconnected,
155
156 #[error("unsupported channel buffer kind: {kind}")]
158 UnsupportedChannelBufferKind {
159 kind: &'static str,
161 },
162}
163
164pub type Result<T> = std::result::Result<T, LavaFlowError>;