1#[cfg(feature = "std")]
4use thiserror::Error;
5
6#[cfg(not(feature = "std"))]
7use core::fmt;
8
9#[cfg(feature = "std")]
11#[derive(Error, Debug, Clone, PartialEq)]
12pub enum CoreError {
13 #[error("Invalid dimension: expected {expected}, got {actual}")]
15 InvalidDimension { expected: usize, actual: usize },
16
17 #[error("Division by zero")]
19 DivisionByZero,
20
21 #[error("Numerical instability detected")]
23 NumericalInstability,
24
25 #[error("Invalid basis vector index: {0} (max: {1})")]
27 InvalidBasisIndex(usize, usize),
28
29 #[error("Matrix is singular and cannot be inverted")]
31 SingularMatrix,
32
33 #[error("Invalid metric signature: positive {positive} + negative {negative} + zero {zero} != dimension {dimension}")]
35 InvalidSignature {
36 positive: usize,
37 negative: usize,
38 zero: usize,
39 dimension: usize,
40 },
41}
42
43#[cfg(not(feature = "std"))]
45#[derive(Debug, Clone, PartialEq)]
46pub enum CoreError {
47 InvalidDimension { expected: usize, actual: usize },
49
50 DivisionByZero,
52
53 NumericalInstability,
55
56 InvalidBasisIndex(usize, usize),
58
59 SingularMatrix,
61
62 InvalidSignature {
64 positive: usize,
65 negative: usize,
66 zero: usize,
67 dimension: usize,
68 },
69}
70
71#[cfg(not(feature = "std"))]
72impl fmt::Display for CoreError {
73 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
74 match self {
75 CoreError::InvalidDimension { expected, actual } => {
76 write!(
77 f,
78 "Invalid dimension: expected {}, got {}",
79 expected, actual
80 )
81 }
82 CoreError::DivisionByZero => {
83 write!(f, "Division by zero")
84 }
85 CoreError::NumericalInstability => {
86 write!(f, "Numerical instability detected")
87 }
88 CoreError::InvalidBasisIndex(idx, max) => {
89 write!(f, "Invalid basis vector index: {} (max: {})", idx, max)
90 }
91 CoreError::SingularMatrix => {
92 write!(f, "Matrix is singular and cannot be inverted")
93 }
94 CoreError::InvalidSignature {
95 positive,
96 negative,
97 zero,
98 dimension,
99 } => {
100 write!(
101 f,
102 "Invalid metric signature: positive {} + negative {} + zero {} != dimension {}",
103 positive, negative, zero, dimension
104 )
105 }
106 }
107 }
108}
109
110pub type CoreResult<T> = Result<T, CoreError>;