1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use alloc::string::String;

use miden_formatting::hex::DisplayHex;

// INPUT ERROR
// ================================================================================================

#[derive(Clone, Debug, thiserror::Error)]
pub enum InputError {
    #[error("{:#x} is a duplicate of the current merkle set", DisplayHex(.0.as_slice()))]
    DuplicateAdviceRoot([u8; 32]),
    #[error("number of input values can not exceed {0}, but {1} was provided")]
    InputLengthExceeded(usize, usize),
    #[error("{0} is not a valid field element: {1}")]
    NotFieldElement(u64, String),
}

// OUTPUT ERROR
// ================================================================================================

#[derive(Clone, Debug, thiserror::Error)]
pub enum OutputError {
    #[error("overflow addresses contains invalid field element: {0}")]
    InvalidOverflowAddress(String),
    #[error("overflow addresses length is {0}, but expected {1}")]
    InvalidOverflowAddressLength(usize, usize),
    #[error("stack contains an invalid field element: {0}")]
    InvalidStackElement(String),
    #[error("too many elements for output stack, {0} elements")]
    OutputSizeTooBig(usize),
}

// KERNEL ERROR
// ================================================================================================

#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum KernelError {
    #[error("kernel cannot have duplicated procedures")]
    DuplicatedProcedures,
    #[error("kernel can have at most {0} procedures, received {1}")]
    TooManyProcedures(usize, usize),
}