feagi_npu_runtime/traits/
error.rs1use core::fmt;
7
8#[cfg(feature = "std")]
9extern crate std;
10
11#[cfg(feature = "std")]
12use std::string::String;
13
14#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum RuntimeError {
17 CapacityExceeded {
19 requested: usize,
21 available: usize,
23 },
24
25 OutOfMemory {
27 requested_bytes: usize,
29 },
30
31 #[cfg(feature = "std")]
33 InvalidParameters(String),
34
35 #[cfg(feature = "std")]
37 InvalidOperation(String),
38
39 #[cfg(feature = "std")]
41 PlatformNotSupported(String),
42
43 #[cfg(feature = "std")]
45 StorageError(String),
46
47 #[cfg(not(feature = "std"))]
49 GenericError,
50}
51
52impl fmt::Display for RuntimeError {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 match self {
55 RuntimeError::CapacityExceeded {
56 requested,
57 available,
58 } => {
59 write!(
60 f,
61 "Capacity exceeded: requested {}, available {}",
62 requested, available
63 )
64 }
65 RuntimeError::OutOfMemory { requested_bytes } => {
66 write!(f, "Out of memory: requested {} bytes", requested_bytes)
67 }
68 #[cfg(feature = "std")]
69 RuntimeError::InvalidParameters(msg) => {
70 write!(f, "Invalid parameters: {}", msg)
71 }
72 #[cfg(feature = "std")]
73 RuntimeError::InvalidOperation(msg) => {
74 write!(f, "Invalid operation: {}", msg)
75 }
76 #[cfg(feature = "std")]
77 RuntimeError::PlatformNotSupported(platform) => {
78 write!(f, "Platform not supported: {}", platform)
79 }
80 #[cfg(feature = "std")]
81 RuntimeError::StorageError(msg) => {
82 write!(f, "Storage error: {}", msg)
83 }
84 #[cfg(not(feature = "std"))]
85 RuntimeError::GenericError => {
86 write!(f, "Runtime error")
87 }
88 }
89 }
90}
91
92#[cfg(feature = "std")]
93impl std::error::Error for RuntimeError {}
94
95pub type Result<T> = core::result::Result<T, RuntimeError>;