stark_evm_adapter/
errors.rs

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use ethers::{
    abi::{
        ethereum_types::{FromDecStrErr, FromStrRadixErr},
        EncodePackedError,
    },
    utils::hex::FromHexError,
};
use num_bigint::ParseBigIntError;
use std::num::ParseIntError;
use thiserror::Error;

// Define the custom error type using `thiserror`.
#[derive(Error, Debug)]
pub enum ParseError {
    #[error("regex error")]
    RegexError,
    #[error("parse u256 error")]
    ParseU256Error,
    #[error("parse integer error")]
    ParseIntError,
    #[error("parse bigint error")]
    ParseBigUIntError,
    #[error("hex extraction error")]
    HexExtractionError,
    #[error("invalid line format")]
    InvalidLineFormat,
    #[error("ether encoding error")]
    EtherEncodingError,
}

impl From<FromDecStrErr> for ParseError {
    fn from(_: FromDecStrErr) -> Self {
        ParseError::ParseU256Error
    }
}

impl From<FromStrRadixErr> for ParseError {
    fn from(_: FromStrRadixErr) -> Self {
        ParseError::ParseU256Error
    }
}

impl From<ParseBigIntError> for ParseError {
    fn from(_: ParseBigIntError) -> Self {
        ParseError::ParseBigUIntError
    }
}

impl From<regex::Error> for ParseError {
    fn from(_: regex::Error) -> Self {
        ParseError::RegexError
    }
}

impl From<ParseIntError> for ParseError {
    fn from(_: ParseIntError) -> Self {
        ParseError::RegexError
    }
}

impl From<FromHexError> for ParseError {
    fn from(_: FromHexError) -> Self {
        ParseError::InvalidLineFormat
    }
}

impl From<EncodePackedError> for ParseError {
    fn from(_: EncodePackedError) -> Self {
        ParseError::EtherEncodingError
    }
}