-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror.rs
More file actions
103 lines (96 loc) · 3.7 KB
/
Copy patherror.rs
File metadata and controls
103 lines (96 loc) · 3.7 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::DecimalFloat;
use alloy::hex::FromHexError;
use alloy::primitives::{Bytes, FixedBytes};
use alloy::sol_types::SolError;
use revm::context::result::{EVMError, HaltReason, Output, SuccessReason};
use std::thread::AccessError;
use thiserror::Error;
use wasm_bindgen_utils::prelude::js_sys::{Error as JsError, RangeError};
use wasm_bindgen_utils::result::WasmEncodedError;
#[derive(Debug, Error)]
pub enum FloatError {
#[error("EVM error: {0}")]
Evm(#[from] EVMError<std::convert::Infallible>),
#[error("Float execution reverted with output: {0}")]
Revert(Bytes),
#[error("Float execution halted with reason: {0:?}")]
Halt(HaltReason),
#[error("Execution ended for non-return reason. Reason: {0:?}. Output: {1:?}")]
UnexpectedSuccess(SuccessReason, Output),
#[error(transparent)]
AlloySolTypes(#[from] alloy::sol_types::Error),
#[error("Decimal Float error: {0:?}")]
DecimalFloat(Box<DecimalFloat::DecimalFloatErrors>),
#[error("Decimal Float error selector: {0:?}")]
DecimalFloatSelector(Result<DecimalFloatErrorSelector, FixedBytes<4>>),
#[error(transparent)]
Access(#[from] AccessError),
#[error("Invalid hex string: {0}")]
InvalidHex(String),
#[error(transparent)]
AlloyFromHexError(#[from] FromHexError),
#[error(transparent)]
AlloyParseError(#[from] alloy::primitives::ruint::ParseError),
#[error(transparent)]
AlloyParseSignedError(#[from] alloy::primitives::ParseSignedError),
#[error("Wasm bindgen js_sys threw error: {0}")]
JsSysError(String),
}
#[derive(Debug)]
pub enum DecimalFloatErrorSelector {
CoefficientOverflow,
ExponentOverflow,
ExponentUnderflow,
FixedDecimalOverflow,
Log10Negative,
Log10Zero,
LossyConversionFromFloat,
NegativeFixedDecimalConversion,
WithTargetExponentOverflow,
}
impl TryFrom<FixedBytes<4>> for DecimalFloatErrorSelector {
type Error = FixedBytes<4>;
fn try_from(error_selector: FixedBytes<4>) -> Result<Self, Self::Error> {
let FixedBytes(bytes) = error_selector;
match bytes {
<DecimalFloat::CoefficientOverflow as SolError>::SELECTOR => {
Ok(Self::CoefficientOverflow)
}
<DecimalFloat::ExponentOverflow as SolError>::SELECTOR => Ok(Self::ExponentOverflow),
<DecimalFloat::ExponentUnderflow as SolError>::SELECTOR => Ok(Self::ExponentUnderflow),
<DecimalFloat::FixedDecimalOverflow as SolError>::SELECTOR => {
Ok(Self::FixedDecimalOverflow)
}
<DecimalFloat::Log10Negative as SolError>::SELECTOR => Ok(Self::Log10Negative),
<DecimalFloat::Log10Zero as SolError>::SELECTOR => Ok(Self::Log10Zero),
<DecimalFloat::LossyConversionFromFloat as SolError>::SELECTOR => {
Ok(Self::LossyConversionFromFloat)
}
<DecimalFloat::NegativeFixedDecimalConversion as SolError>::SELECTOR => {
Ok(Self::NegativeFixedDecimalConversion)
}
<DecimalFloat::WithTargetExponentOverflow as SolError>::SELECTOR => {
Ok(Self::WithTargetExponentOverflow)
}
_ => Err(error_selector),
}
}
}
impl From<FloatError> for WasmEncodedError {
fn from(value: FloatError) -> Self {
WasmEncodedError {
msg: value.to_string(),
readable_msg: value.to_string(), // todo: add detailed readable msg for errors
}
}
}
impl From<JsError> for FloatError {
fn from(value: JsError) -> Self {
FloatError::JsSysError(value.to_string().into())
}
}
impl From<RangeError> for FloatError {
fn from(value: RangeError) -> Self {
FloatError::JsSysError(value.to_string().into())
}
}