1use ethrex_levm::errors::{DatabaseError as LevmDatabaseError, InternalError, VMError};
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum EvmError {
6 #[error("Invalid Transaction: {0}")]
7 Transaction(String),
8 #[error("Invalid Header: {0}")]
9 Header(String),
10 #[error("DB error: {0}")]
11 DB(String),
12 #[error("{0}")]
13 Precompile(String),
14 #[error("Invalid EVM or EVM not supported: {0}")]
15 InvalidEVM(String),
16 #[error("{0}")]
17 Custom(String),
18 #[error("Invalid deposit request layout")]
19 InvalidDepositRequest,
20 #[error("System call failed: {0}")]
21 SystemContractCallFailed(String),
22}
23
24impl From<VMError> for EvmError {
25 fn from(value: VMError) -> Self {
26 if value.should_propagate() {
27 EvmError::Custom(value.to_string())
28 } else {
29 EvmError::Transaction(value.to_string())
31 }
32 }
33}
34
35impl From<LevmDatabaseError> for EvmError {
36 fn from(value: LevmDatabaseError) -> Self {
37 EvmError::DB(value.to_string())
38 }
39}
40
41impl From<InternalError> for EvmError {
42 fn from(value: InternalError) -> Self {
43 match value {
44 InternalError::Database(err) => err.into(),
45 other => EvmError::Custom(other.to_string()),
46 }
47 }
48}