Skip to main content

sentri_analyzer_evm/
errors.rs

1#![allow(missing_docs)]
2//! Error types for EVM analysis operations.
3
4use thiserror::Error;
5
6/// Result type for EVM analyzer operations.
7pub type AnalysisResult<T> = Result<T, AnalysisError>;
8
9/// Comprehensive error type for EVM analysis failures.
10#[derive(Error, Debug)]
11pub enum AnalysisError {
12    /// Error compiling Solidity source with solc.
13    #[error("Solidity compilation failed: {0}")]
14    CompilationError(String),
15
16    /// Error parsing JSON AST.
17    #[error("AST parsing error: {0}")]
18    AstParsingError(String),
19
20    /// Error analyzing bytecode.
21    #[error("Bytecode analysis error: {0}")]
22    BytecodeAnalysisError(String),
23
24    /// Error building control flow graph.
25    #[error("Control flow graph construction error: {0}")]
26    CfgError(String),
27
28    /// Error during data flow analysis.
29    #[error("Data flow analysis error: {0}")]
30    DataFlowError(String),
31
32    /// Error during symbolic execution.
33    #[error("Symbolic execution error: {0}")]
34    SymbolicExecutionError(String),
35
36    /// Error during contract execution.
37    #[error("Contract execution error: {0}")]
38    ExecutionError(String),
39
40    /// Generic I/O error.
41    #[error("I/O error: {0}")]
42    IoError(#[from] std::io::Error),
43
44    /// JSON serialization/deserialization error.
45    #[error("JSON error: {0}")]
46    JsonError(#[from] serde_json::Error),
47
48    /// Generic internal error.
49    #[error("Internal error: {0}")]
50    Internal(String),
51}
52
53impl AnalysisError {
54    /// Create a compilation error.
55    pub fn compilation(msg: impl Into<String>) -> Self {
56        AnalysisError::CompilationError(msg.into())
57    }
58
59    /// Create an AST parsing error.
60    pub fn ast_parsing(msg: impl Into<String>) -> Self {
61        AnalysisError::AstParsingError(msg.into())
62    }
63
64    /// Create a bytecode analysis error.
65    pub fn bytecode(msg: impl Into<String>) -> Self {
66        AnalysisError::BytecodeAnalysisError(msg.into())
67    }
68
69    /// Create a CFG construction error.
70    pub fn cfg(msg: impl Into<String>) -> Self {
71        AnalysisError::CfgError(msg.into())
72    }
73
74    /// Create a data flow analysis error.
75    pub fn dataflow(msg: impl Into<String>) -> Self {
76        AnalysisError::DataFlowError(msg.into())
77    }
78
79    /// Create a symbolic execution error.
80    pub fn symbolic(msg: impl Into<String>) -> Self {
81        AnalysisError::SymbolicExecutionError(msg.into())
82    }
83
84    /// Create an execution error.
85    pub fn execution(msg: impl Into<String>) -> Self {
86        AnalysisError::ExecutionError(msg.into())
87    }
88
89    /// Create an internal error.
90    pub fn internal(msg: impl Into<String>) -> Self {
91        AnalysisError::Internal(msg.into())
92    }
93}