hpt_common/error/
memory.rs

1use std::panic::Location;
2
3use thiserror::Error;
4
5/// Errors related to memory operations such as allocation, layout validation
6#[derive(Debug, Error)]
7pub enum MemoryError {
8    /// Error that occurs when memory allocation fails
9    #[error("Failed to allocate {size} bytes on {device}{id} at {location}")]
10    AllocationFailed {
11        /// Name of the device where the allocation failed
12        device: String,
13        /// ID of the device where the allocation failed
14        id: usize,
15        /// Size of the memory that was attempted to be allocated
16        size: usize,
17        /// Source of the error
18        #[source]
19        source: Option<Box<dyn std::error::Error + Send + Sync>>,
20        /// Location where the error occurred
21        location: &'static Location<'static>,
22    },
23
24    /// Error that occurs when an invalid memory layout is detected
25    #[error("Invalid memory layout: {message} at {location}")]
26    InvalidLayout {
27        /// Message describing the invalid layout
28        message: String,
29        /// Location where the error occurred
30        location: &'static Location<'static>,
31    },
32    /// used when the reference count overflow
33    #[error("reference count overflow for device {device}{id}, at {location}")]
34    ReferenceCountOverflow {
35        /// Name of the device where the allocation failed
36        device: String,
37        /// ID of the device where the allocation failed
38        id: usize,
39        /// Location where error occurred
40        location: &'static Location<'static>,
41    },
42}