1#[derive(Debug)]
5pub enum Error {
6 ProofCatCore(proof_cat_core::Error),
8 Plonkish(plonkish_cat::Error),
10 FieldCat(field_cat::Error),
12 ColumnOutOfBounds {
14 index: usize,
16 column_count: usize,
18 },
19 EmptyTrace,
21 ColumnCountMismatch {
23 expected: usize,
25 actual: usize,
27 },
28 TraceNotPowerOfTwo {
30 row_count: usize,
32 },
33 UnsatisfiedAirConstraint {
35 row: usize,
37 },
38 NoConstraints,
40 InsufficientRows {
42 row_count: usize,
44 },
45 RowLengthMismatch {
47 row: usize,
49 expected: usize,
51 actual: usize,
53 },
54}
55
56impl core::fmt::Display for Error {
57 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58 match self {
59 Self::ProofCatCore(e) => write!(f, "proof-cat-core error: {e}"),
60 Self::Plonkish(e) => write!(f, "plonkish-cat error: {e}"),
61 Self::FieldCat(e) => write!(f, "field-cat error: {e}"),
62 Self::ColumnOutOfBounds {
63 index,
64 column_count,
65 } => write!(
66 f,
67 "column index {index} out of bounds (column count: {column_count})"
68 ),
69 Self::EmptyTrace => write!(f, "trace has zero rows"),
70 Self::ColumnCountMismatch { expected, actual } => {
71 write!(
72 f,
73 "column count mismatch: expected {expected}, got {actual}"
74 )
75 }
76 Self::TraceNotPowerOfTwo { row_count } => {
77 write!(f, "trace row count {row_count} is not a power of two")
78 }
79 Self::UnsatisfiedAirConstraint { row } => {
80 write!(
81 f,
82 "AIR constraint not satisfied at row pair ({row}, {})",
83 row + 1
84 )
85 }
86 Self::NoConstraints => write!(f, "AIR has no constraints"),
87 Self::InsufficientRows { row_count } => {
88 write!(f, "trace has {row_count} rows, need at least 2")
89 }
90 Self::RowLengthMismatch {
91 row,
92 expected,
93 actual,
94 } => write!(f, "row {row} has {actual} elements, expected {expected}"),
95 }
96 }
97}
98
99impl std::error::Error for Error {
100 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
101 match self {
102 Self::ProofCatCore(e) => Some(e),
103 Self::Plonkish(e) => Some(e),
104 Self::FieldCat(e) => Some(e),
105 Self::ColumnOutOfBounds { .. }
106 | Self::EmptyTrace
107 | Self::ColumnCountMismatch { .. }
108 | Self::TraceNotPowerOfTwo { .. }
109 | Self::UnsatisfiedAirConstraint { .. }
110 | Self::NoConstraints
111 | Self::InsufficientRows { .. }
112 | Self::RowLengthMismatch { .. } => None,
113 }
114 }
115}
116
117impl From<proof_cat_core::Error> for Error {
118 fn from(e: proof_cat_core::Error) -> Self {
119 Self::ProofCatCore(e)
120 }
121}
122
123impl From<plonkish_cat::Error> for Error {
124 fn from(e: plonkish_cat::Error) -> Self {
125 Self::Plonkish(e)
126 }
127}
128
129impl From<field_cat::Error> for Error {
130 fn from(e: field_cat::Error) -> Self {
131 Self::FieldCat(e)
132 }
133}