1#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
26pub enum Error {
27 #[error("{op}: axis {axis} out of bounds for rank {rank}")]
28 AxisOutOfBounds {
29 op: &'static str,
30 axis: usize,
31 rank: usize,
32 },
33 #[error("{op}: duplicate {role} axis {axis}")]
34 DuplicateAxis {
35 op: &'static str,
36 axis: usize,
37 role: &'static str,
38 },
39 #[error("{op}: axis {axis} appears in both {first_role} and {second_role}")]
40 AxisRoleConflict {
41 op: &'static str,
42 axis: usize,
43 first_role: &'static str,
44 second_role: &'static str,
45 },
46 #[error("{op}: shape mismatch lhs={lhs:?} rhs={rhs:?}")]
47 ShapeMismatch {
48 op: &'static str,
49 lhs: Vec<usize>,
50 rhs: Vec<usize>,
51 },
52 #[error("{op}: rank mismatch expected {expected}, actual {actual}")]
53 RankMismatch {
54 op: &'static str,
55 expected: usize,
56 actual: usize,
57 },
58 #[error("{op}: dtype mismatch lhs={lhs:?} rhs={rhs:?}")]
59 DTypeMismatch {
60 op: &'static str,
61 lhs: crate::DType,
62 rhs: crate::DType,
63 },
64 #[error("{op}: unsupported dtype conversion from {from:?} to {to:?}: {message}")]
65 UnsupportedDTypeConversion {
66 op: &'static str,
67 from: crate::DType,
68 to: crate::DType,
69 message: String,
70 },
71 #[error("{op}: invalid config: {message}")]
72 InvalidConfig { op: &'static str, message: String },
73 #[error("{op}: backend failure: {message}")]
74 BackendFailure { op: &'static str, message: String },
75 #[error("missing runtime value for slot {slot}")]
76 MissingValue { slot: usize },
77}
78
79impl Error {
80 pub fn backend_failure(op: &'static str, message: impl std::fmt::Display) -> Self {
97 Self::BackendFailure {
98 op,
99 message: message.to_string(),
100 }
101 }
102}
103
104pub type Result<T> = std::result::Result<T, Error>;